-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
28 lines (20 loc) · 1.03 KB
/
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
import openai
import yaml
# read api key from keys.yaml
with open("keys.yaml", "r") as f:
keys = yaml.load(f, Loader=yaml.FullLoader)
openai.api_key = keys["key"]
def get_answer(phrase: str):
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": phrase}])
return completion.choices[0].message.content
def translator(phrase: str, language: str):
if language == "English":
return phrase
elif language == "Spanish":
return get_answer(f"Translate from Spanish to English: {phrase}")
elif language == "German":
return get_answer(f"Translate from German to English: {phrase}")
else:
raise ValueError("Language not supported")
def text_generator(phrase: str):
return get_answer(f"Convert the following text or bullet points into a report. Focus on the facts and only give information that is actually included in the text. The report is technical, so there should be no sentiments. There should not be a conclusion. Text: {phrase}")