Spaces:
Runtime error
Runtime error
commit
Browse files- app.py +34 -1
- requirements.txt +1 -1
app.py
CHANGED
@@ -5,6 +5,38 @@ import openai
|
|
5 |
class OpenAIUtils:
|
6 |
|
7 |
@classmethod
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def use_openai_davinci_base(cls, prompt):
|
9 |
"""
|
10 |
Use OpenAI's GPT-3 model, Davinci, to generate text based on the given prompt
|
@@ -43,7 +75,8 @@ class CalqOffer:
|
|
43 |
【待遇】
|
44 |
"""
|
45 |
print(prompt)
|
46 |
-
return OpenAIUtils.use_openai_davinci_base(prompt)
|
|
|
47 |
|
48 |
def post_process_mail_reply(offer_reply):
|
49 |
remove_list = ["(箇条書き)"]
|
|
|
5 |
class OpenAIUtils:
|
6 |
|
7 |
@classmethod
|
8 |
+
def use_openai_chatgpt_base(cls, prompt):
|
9 |
+
"""
|
10 |
+
Use OpenAI's GPT-3 model, Davinci, to generate text based on the given prompt
|
11 |
+
"""
|
12 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
13 |
+
|
14 |
+
try:
|
15 |
+
# res = openai.ChatCompletion.create(
|
16 |
+
res = openai.Completion.create(
|
17 |
+
model="gpt-3.5-turbo",
|
18 |
+
prompt=prompt,
|
19 |
+
max_tokens=1024,
|
20 |
+
temperature=0.5,
|
21 |
+
messages=[
|
22 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
23 |
+
# {"role": "user", "content": "Who won the world series in 2020?"},
|
24 |
+
# {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
|
25 |
+
# {"role": "user", "content": "Where was it played?"}
|
26 |
+
]
|
27 |
+
)
|
28 |
+
# res = openai.Completion.create(
|
29 |
+
# model="text-davinci-003",
|
30 |
+
# prompt=prompt,
|
31 |
+
# max_tokens=1024,
|
32 |
+
# temperature=0.5
|
33 |
+
# )
|
34 |
+
string = res.choices[0].text
|
35 |
+
except openai.error.InvalidRequestError as e:
|
36 |
+
print(f"Error: {e}")
|
37 |
+
return None
|
38 |
+
return string
|
39 |
+
@classmethod
|
40 |
def use_openai_davinci_base(cls, prompt):
|
41 |
"""
|
42 |
Use OpenAI's GPT-3 model, Davinci, to generate text based on the given prompt
|
|
|
75 |
【待遇】
|
76 |
"""
|
77 |
print(prompt)
|
78 |
+
# return OpenAIUtils.use_openai_davinci_base(prompt)
|
79 |
+
return OpenAIUtils.use_openai_chatgpt_base(prompt)
|
80 |
|
81 |
def post_process_mail_reply(offer_reply):
|
82 |
remove_list = ["(箇条書き)"]
|
requirements.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
openai
|
|
|
1 |
+
openai==0.27.0
|