Spaces:
Sleeping
Sleeping
lachie0232
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,19 @@ import openai
|
|
2 |
import gradio as gr
|
3 |
|
4 |
# Set up OpenAI API key
|
5 |
-
|
6 |
|
7 |
# Define a function to call the OpenAI API
|
8 |
def chatbot(input_text):
|
9 |
try:
|
10 |
-
|
11 |
-
response = openai.Completion.create(
|
12 |
model="gpt-3.5-turbo", # You can change this to GPT-4 or others
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
)
|
16 |
-
return response['choices'][0]['
|
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 |
|