Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,18 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import openai
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 6 |
-
try:
|
| 7 |
-
response = openai.ChatCompletion.create(...)
|
| 8 |
-
except Exception as e:
|
| 9 |
-
return f"Error: {str(e)}"
|
| 10 |
-
|
| 11 |
-
def simple_agent(message, history):
|
| 12 |
-
response = openai.ChatCompletion.create(
|
| 13 |
-
model="gpt-3.5-turbo",
|
| 14 |
-
messages=[
|
| 15 |
-
{"role": "system", "content": "You are a helpful assistant."}
|
| 16 |
-
] + [{"role": "user", "content": m} for m, _ in history] + [{"role": "user", "content": message}]
|
| 17 |
-
)
|
| 18 |
-
return response.choices[0].message["content"]
|
| 19 |
-
|
| 20 |
-
iface = gr.ChatInterface(
|
| 21 |
-
simple_agent,
|
| 22 |
-
title="Simple AI Agent",
|
| 23 |
-
type="messages" # <--- this avoids the deprecation warning
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
iface.launch(share=True) # <--- this creates a public link
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
import os
|
| 4 |
|
| 5 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def simple_agent(message):
|
| 8 |
+
try:
|
| 9 |
+
response = openai.ChatCompletion.create(
|
| 10 |
+
model="gpt-3.5-turbo",
|
| 11 |
+
messages=[{"role": "user", "content": message}]
|
| 12 |
+
)
|
| 13 |
+
return response.choices[0].message["content"]
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error: {str(e)}"
|
| 16 |
|
| 17 |
+
iface = gr.Interface(fn=simple_agent, inputs="text", outputs="text", title="Simple AI Agent")
|
| 18 |
+
iface.launch()
|