-
Notifications
You must be signed in to change notification settings - Fork 0
/
information_extraction_utils.py
38 lines (34 loc) · 1.19 KB
/
information_extraction_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import openai
from retry import retry
from secret_key import key
openai.api_key = key # You will need your own OpenAI API key.
@retry()
def contains_number(text):
for i in reversed(range(1,27)):
if str(i) in text:
return str(i)
api_response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": f"Write the number, in digits, contained in the following text. Write the number and nothing else (no punctuation). \
If the text does not contain a number, just say 'no number': {text}"}
]
)
answer = api_response['choices'][0]['message']['content']
return answer.lower()
# @retry()
# def wants_to_end(text):
# api_response = openai.ChatCompletion.create(
# model="gpt-3.5-turbo",
# messages=[
# {"role": "system",
# "content": f"does the speaker of the following utterance imply that they wish to end the conversation and leave? (reply just yes or no): {text}"}
# ]
# )
# answer = api_response['choices'][0]['message']['content']
# if "yes" in answer.lower():
# answer = True
# else:
# answer = False
# return answer