Jack7510 commited on
Commit
54fb2a7
1 Parent(s): c3e79ab

Update app.py

Browse files

use gpt-3.5-turbo

Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -5,24 +5,19 @@ import os
5
  # Set up the OpenAI API credentials
6
  # openai.api_key = os.environ["OPENAI_API_KEY"]
7
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
8
 
9
  # Define the chatbot function
10
  def chatbot(text):
11
- # Call the OpenAI API to generate a response
12
- response = openai.Completion.create(
13
- model="text-davinci-003",
14
- prompt=text,
15
- max_tokens=1024,
16
- n=1,
17
- stop=None,
18
- temperature=0.5,
19
- )
20
 
21
  # Extract the generated response and return it
22
- return response.choices[0].text.strip()
23
 
24
  # Create the Gradio interface
25
- iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-3 Chatbot")
26
 
27
  # Launch the interface
28
  iface.launch()
 
5
  # Set up the OpenAI API credentials
6
  # openai.api_key = os.environ["OPENAI_API_KEY"]
7
  openai.api_key = os.getenv("OPENAI_API_KEY")
8
+ model = "gpt-3.5-turbo"
9
 
10
  # Define the chatbot function
11
  def chatbot(text):
12
+
13
+ # Call OpenAI API to generate text completion
14
+ completion = openai.ChatCompletion.create(model=model, messages=[{"role": "user", "content": text}])
 
 
 
 
 
 
15
 
16
  # Extract the generated response and return it
17
+ return completion.choices[0].message.content
18
 
19
  # Create the Gradio interface
20
+ iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-3.5 Turbo Chatbot")
21
 
22
  # Launch the interface
23
  iface.launch()