lachie0232 commited on
Commit
e5b5bad
·
verified ·
1 Parent(s): 6c7eead

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -4,14 +4,19 @@ import gradio as gr
4
  # Set up OpenAI API key
5
  openai.api_key = "your-openai-secret-key"
6
 
7
- # Define a function to call the OpenAI API
8
  def chatbot(input_text):
9
- response = openai.Completion.create(
10
- engine="text-davinci-003", # You can choose another engine if desired
11
- prompt=input_text,
12
- max_tokens=150
13
- )
14
- return response.choices[0].text.strip()
 
 
 
 
 
15
 
16
  # Create the Gradio interface
17
  iface = gr.Interface(
@@ -23,3 +28,4 @@ iface = gr.Interface(
23
 
24
  # Launch the interface
25
  iface.launch()
 
 
4
  # Set up OpenAI API key
5
  openai.api_key = "your-openai-secret-key"
6
 
7
+ # Define a function to call the OpenAI API (new method)
8
  def chatbot(input_text):
9
+ try:
10
+ response = openai.chat_completions.create(
11
+ model="gpt-3.5-turbo", # You can change this model if you have access to GPT-4 or other models
12
+ messages=[
13
+ {"role": "system", "content": "You are a helpful assistant."},
14
+ {"role": "user", "content": input_text},
15
+ ]
16
+ )
17
+ return response['choices'][0]['message']['content'].strip()
18
+ except Exception as e:
19
+ return f"Error: {str(e)}"
20
 
21
  # Create the Gradio interface
22
  iface = gr.Interface(
 
28
 
29
  # Launch the interface
30
  iface.launch()
31
+