Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
-
import
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
|
|
@@ -26,16 +27,18 @@ def generate_response(user_input):
|
|
| 26 |
|
| 27 |
|
| 28 |
# Generate a response using the OpenAI API
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Extract the response from the API output
|
| 41 |
chat_response = response.choices[0].text.strip()
|
|
|
|
| 1 |
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
client = OpenAI()
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
# Generate a response using the OpenAI API
|
| 30 |
+
from openai import OpenAI
|
| 31 |
+
client = OpenAI()
|
| 32 |
+
|
| 33 |
+
response = client.chat.completions.create(
|
| 34 |
+
model="gpt-3.5-turbo-1106",
|
| 35 |
+
response_format={ "type": "json_object" },
|
| 36 |
+
messages=[
|
| 37 |
+
{"role": "system", "content": "You are a helpful assistant designed to output JSON."},
|
| 38 |
+
{"role": "user", "content": "Who won the world series in 2020?"}
|
| 39 |
+
]
|
| 40 |
+
)
|
| 41 |
+
print(response.choices[0].message.content)
|
| 42 |
|
| 43 |
# Extract the response from the API output
|
| 44 |
chat_response = response.choices[0].text.strip()
|