Spaces:
Build error
Build error
hectorjelly
commited on
Commit
•
8e05cfe
1
Parent(s):
0ef7602
Update app.py
Browse files
app.py
CHANGED
@@ -23,15 +23,15 @@ def add_user_text(chat_history, user_text):
|
|
23 |
return chat_history, gr.update(value="", interactive=False)
|
24 |
|
25 |
# Function for the bot to respond
|
26 |
-
def bot_respond(chat_history, openai_gpt_key):
|
27 |
global messages
|
28 |
|
29 |
if openai_gpt_key is not "":
|
30 |
openai.api_key = openai_gpt_key
|
31 |
|
32 |
-
# Generate response from OpenAI Chat API
|
33 |
bot_response = openai.ChatCompletion.create(
|
34 |
-
model=
|
35 |
messages=messages,
|
36 |
)
|
37 |
bot_text = bot_response["choices"][0]["message"]["content"]
|
@@ -51,6 +51,7 @@ def bot_respond(chat_history, openai_gpt_key):
|
|
51 |
# Create a Gradio interface
|
52 |
with gr.Blocks() as demo:
|
53 |
openai_gpt_key = gr.Textbox(label="OpenAI GPT API Key", value="", placeholder="sk..", info="If an error is raised, you need to provide your own GPT keys for this app to function properly")
|
|
|
54 |
clear_btn = gr.Button("Clear for Restart")
|
55 |
chat_history = gr.Chatbot([], elem_id="chat_history").style(height=500)
|
56 |
|
@@ -63,7 +64,7 @@ with gr.Blocks() as demo:
|
|
63 |
# Handle user input and bot response
|
64 |
user_text.submit(
|
65 |
add_user_text, [chat_history, user_text], [chat_history, user_text], queue=False).then(
|
66 |
-
bot_respond, [chat_history, openai_gpt_key], chat_history).then(
|
67 |
lambda: gr.update(interactive=True), None, [user_text], queue=False)
|
68 |
|
69 |
clear_btn.click(lambda: None, None, chat_history, queue=False)
|
|
|
23 |
return chat_history, gr.update(value="", interactive=False)
|
24 |
|
25 |
# Function for the bot to respond
|
26 |
+
def bot_respond(chat_history, openai_gpt_key, model_choice):
|
27 |
global messages
|
28 |
|
29 |
if openai_gpt_key is not "":
|
30 |
openai.api_key = openai_gpt_key
|
31 |
|
32 |
+
# Generate response from OpenAI Chat API using the selected model
|
33 |
bot_response = openai.ChatCompletion.create(
|
34 |
+
model=model_choice,
|
35 |
messages=messages,
|
36 |
)
|
37 |
bot_text = bot_response["choices"][0]["message"]["content"]
|
|
|
51 |
# Create a Gradio interface
|
52 |
with gr.Blocks() as demo:
|
53 |
openai_gpt_key = gr.Textbox(label="OpenAI GPT API Key", value="", placeholder="sk..", info="If an error is raised, you need to provide your own GPT keys for this app to function properly")
|
54 |
+
model_choice = gr.Dropdown(label="Model Options", choices=['gpt-3.5-turbo', 'gpt-4'])
|
55 |
clear_btn = gr.Button("Clear for Restart")
|
56 |
chat_history = gr.Chatbot([], elem_id="chat_history").style(height=500)
|
57 |
|
|
|
64 |
# Handle user input and bot response
|
65 |
user_text.submit(
|
66 |
add_user_text, [chat_history, user_text], [chat_history, user_text], queue=False).then(
|
67 |
+
bot_respond, [chat_history, openai_gpt_key, model_choice], chat_history).then(
|
68 |
lambda: gr.update(interactive=True), None, [user_text], queue=False)
|
69 |
|
70 |
clear_btn.click(lambda: None, None, chat_history, queue=False)
|