smithaneka commited on
Commit
45f74a7
·
verified ·
1 Parent(s): 30534bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -2,16 +2,23 @@ import gradio as gr
2
  import openai
3
  import os
4
 
5
- # Set your OpenAI key here or in Hugging Face Secrets
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- def simple_agent(message):
9
  response = openai.ChatCompletion.create(
10
- model="gpt-3.5-turbo", # or another model
11
- messages=[{"role": "user", "content": message}]
 
 
12
  )
13
- return response.choices[0].message['content']
 
 
 
 
 
 
 
 
14
 
15
- iface = gr.ChatInterface(simple_agent, title="Simple AI Agent")
16
- iface.launch()
17
 
 
2
  import openai
3
  import os
4
 
 
5
  openai.api_key = os.getenv("OPENAI_API_KEY")
6
 
7
+ def simple_agent(message, history):
8
  response = openai.ChatCompletion.create(
9
+ model="gpt-3.5-turbo",
10
+ messages=[
11
+ {"role": "system", "content": "You are a helpful assistant."}
12
+ ] + [{"role": "user", "content": m} for m, _ in history] + [{"role": "user", "content": message}]
13
  )
14
+ return response.choices[0].message["content"]
15
+
16
+ iface = gr.ChatInterface(
17
+ simple_agent,
18
+ title="Simple AI Agent",
19
+ type="messages" # <--- this avoids the deprecation warning
20
+ )
21
+
22
+ iface.launch(share=True) # <--- this creates a public link
23
 
 
 
24