Spaces:
Running
Running
Update app.py
Browse filesuse gpt-3.5-turbo
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 |
-
|
12 |
-
|
13 |
-
|
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
|
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()
|