lachie0232 commited on
Commit
ef39f9e
·
verified ·
1 Parent(s): 574aeef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -2,18 +2,19 @@ import openai
2
  import gradio as gr
3
 
4
  # Set up OpenAI API key
5
- openai.api_key = "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"
6
 
7
  # Define a function to call the OpenAI API
8
  def chatbot(input_text):
9
  try:
10
- # Updated API call for v1.0.0+
11
- response = openai.Completion.create(
12
  model="gpt-3.5-turbo", # You can change this to GPT-4 or others
13
- prompt=input_text,
14
- max_tokens=150
 
 
15
  )
16
- return response['choices'][0]['text'].strip()
17
  except Exception as e:
18
  return f"Error: {str(e)}"
19
 
 
2
  import gradio as gr
3
 
4
  # Set up OpenAI API key
5
+ openai_api_key = "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"
6
 
7
  # Define a function to call the OpenAI API
8
  def chatbot(input_text):
9
  try:
10
+ response = openai.ChatCompletion.create(
 
11
  model="gpt-3.5-turbo", # You can change this to GPT-4 or others
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