Spaces:
Running
Running
KarthickAdopleAI
commited on
Commit
•
dd974ce
1
Parent(s):
59cf6d7
Update headings_extractor.py
Browse files- headings_extractor.py +12 -12
headings_extractor.py
CHANGED
@@ -38,7 +38,11 @@ class HeadingsExtractor:
|
|
38 |
"""
|
39 |
try:
|
40 |
#get response from openai api
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
conversation = [
|
43 |
{"role": "system", "content": "You are a helpful assistant."},
|
44 |
{"role": "user", "content": f"""Extract Headings from given paragraph do not generate jsu extract the headings from paragraph.
|
@@ -46,18 +50,14 @@ class HeadingsExtractor:
|
|
46 |
]
|
47 |
|
48 |
# Call OpenAI GPT-3.5-turbo
|
49 |
-
chat_completion =
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
frequency_penalty=0,
|
56 |
-
presence_penalty=0,
|
57 |
-
stop=None
|
58 |
-
)
|
59 |
response = chat_completion.choices[0].message.content
|
60 |
-
return response
|
61 |
|
62 |
except Exception as e:
|
63 |
# If an error occurs during the key-value extraction process, log the error
|
|
|
38 |
"""
|
39 |
try:
|
40 |
#get response from openai api
|
41 |
+
client = AzureOpenAI(api_key=os.getenv("AZURE_OPENAI_KEY"),
|
42 |
+
api_version="2023-07-01-preview",
|
43 |
+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
44 |
+
)
|
45 |
+
|
46 |
conversation = [
|
47 |
{"role": "system", "content": "You are a helpful assistant."},
|
48 |
{"role": "user", "content": f"""Extract Headings from given paragraph do not generate jsu extract the headings from paragraph.
|
|
|
50 |
]
|
51 |
|
52 |
# Call OpenAI GPT-3.5-turbo
|
53 |
+
chat_completion = client.chat.completions.create(
|
54 |
+
model = "ChatGPT",
|
55 |
+
messages = conversation,
|
56 |
+
max_tokens=1000,
|
57 |
+
temperature=0
|
58 |
+
)
|
|
|
|
|
|
|
|
|
59 |
response = chat_completion.choices[0].message.content
|
60 |
+
return response
|
61 |
|
62 |
except Exception as e:
|
63 |
# If an error occurs during the key-value extraction process, log the error
|