Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# β
Evo Showcase Mode:
|
2 |
|
3 |
import gradio as gr
|
4 |
import openai
|
@@ -7,17 +7,19 @@ from inference import predict as evo_predict
|
|
7 |
# π SET YOUR GPT-3.5 API KEY HERE
|
8 |
openai.api_key = "sk-..." # You must insert your OpenAI API key
|
9 |
|
|
|
|
|
|
|
10 |
def gpt_predict(prompt):
|
11 |
try:
|
12 |
-
|
13 |
-
completion = openai.ChatCompletion.create(
|
14 |
model="gpt-3.5-turbo",
|
15 |
messages=[
|
16 |
-
{"role": "system", "content":
|
17 |
{"role": "user", "content": prompt}
|
18 |
]
|
19 |
)
|
20 |
-
return
|
21 |
except Exception as e:
|
22 |
return f"GPT Error: {str(e)}"
|
23 |
|
|
|
1 |
+
# β
Evo Showcase Mode: Gradio App with GPT-3.5 Comparison (openai>=1.0 fix)
|
2 |
|
3 |
import gradio as gr
|
4 |
import openai
|
|
|
7 |
# π SET YOUR GPT-3.5 API KEY HERE
|
8 |
openai.api_key = "sk-..." # You must insert your OpenAI API key
|
9 |
|
10 |
+
# β
Use the new openai>=1.0.0 API
|
11 |
+
client = openai.OpenAI()
|
12 |
+
|
13 |
def gpt_predict(prompt):
|
14 |
try:
|
15 |
+
response = client.chat.completions.create(
|
|
|
16 |
model="gpt-3.5-turbo",
|
17 |
messages=[
|
18 |
+
{"role": "system", "content": "You're a commonsense reasoning assistant. Only say: Solution 1 or Solution 2."},
|
19 |
{"role": "user", "content": prompt}
|
20 |
]
|
21 |
)
|
22 |
+
return response.choices[0].message.content.strip()
|
23 |
except Exception as e:
|
24 |
return f"GPT Error: {str(e)}"
|
25 |
|