Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ client = openai.OpenAI(
|
|
8 |
)
|
9 |
|
10 |
# Function to handle predictions
|
11 |
-
def predict(inputs, top_p, temperature,
|
12 |
# Build the system prompt if provided
|
13 |
messages = []
|
14 |
if system_prompt:
|
@@ -39,7 +39,7 @@ def predict(inputs, top_p, temperature, openai_api_key, system_prompt, chat_coun
|
|
39 |
history.append(inputs)
|
40 |
|
41 |
# Using the proxy API to get the response
|
42 |
-
response = client.
|
43 |
model=payload["model"],
|
44 |
messages=payload["messages"],
|
45 |
temperature=payload["temperature"],
|
@@ -72,7 +72,7 @@ def reset_textbox():
|
|
72 |
# UI Components
|
73 |
title = """<h1 align="center">Customizable Chatbot with OpenAI API</h1>"""
|
74 |
description = """
|
75 |
-
Explore the outputs of a GPT-3.5 model, with the ability to customize system prompts
|
76 |
"""
|
77 |
|
78 |
with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
|
@@ -80,7 +80,8 @@ with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-r
|
|
80 |
|
81 |
gr.HTML(title)
|
82 |
with gr.Column(elem_id="col_container"):
|
83 |
-
|
|
|
84 |
system_prompt = gr.Textbox(placeholder="Enter system prompt (optional)", label="System Prompt", lines=2)
|
85 |
chatbot = gr.Chatbot(elem_id='chatbot')
|
86 |
inputs = gr.Textbox(placeholder="Type your message here!", label="Input", lines=1)
|
@@ -95,7 +96,7 @@ with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-r
|
|
95 |
temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature")
|
96 |
|
97 |
# Submit input for model prediction with the send button
|
98 |
-
send_btn.click(predict, [inputs, top_p, temperature,
|
99 |
[chatbot, state, chat_counter])
|
100 |
reset_btn.click(reset_textbox, [], [inputs])
|
101 |
inputs.submit(reset_textbox, [], [inputs])
|
|
|
8 |
)
|
9 |
|
10 |
# Function to handle predictions
|
11 |
+
def predict(inputs, top_p, temperature, system_prompt, chat_counter, chatbot=[], history=[]):
|
12 |
# Build the system prompt if provided
|
13 |
messages = []
|
14 |
if system_prompt:
|
|
|
39 |
history.append(inputs)
|
40 |
|
41 |
# Using the proxy API to get the response
|
42 |
+
response = client.ChatCompletion.create(
|
43 |
model=payload["model"],
|
44 |
messages=payload["messages"],
|
45 |
temperature=payload["temperature"],
|
|
|
72 |
# UI Components
|
73 |
title = """<h1 align="center">Customizable Chatbot with OpenAI API</h1>"""
|
74 |
description = """
|
75 |
+
Explore the outputs of a GPT-3.5 model, with the ability to customize system prompts and interact with a history of conversation logs.
|
76 |
"""
|
77 |
|
78 |
with gr.Blocks(css="""#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
|
|
|
80 |
|
81 |
gr.HTML(title)
|
82 |
with gr.Column(elem_id="col_container"):
|
83 |
+
# Removed the API key input field
|
84 |
+
# openai_api_key = gr.Textbox(type='password', label="Enter your OpenAI API key here")
|
85 |
system_prompt = gr.Textbox(placeholder="Enter system prompt (optional)", label="System Prompt", lines=2)
|
86 |
chatbot = gr.Chatbot(elem_id='chatbot')
|
87 |
inputs = gr.Textbox(placeholder="Type your message here!", label="Input", lines=1)
|
|
|
96 |
temperature = gr.Slider(minimum=0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature")
|
97 |
|
98 |
# Submit input for model prediction with the send button
|
99 |
+
send_btn.click(predict, [inputs, top_p, temperature, system_prompt, chat_counter, chatbot, state],
|
100 |
[chatbot, state, chat_counter])
|
101 |
reset_btn.click(reset_textbox, [], [inputs])
|
102 |
inputs.submit(reset_textbox, [], [inputs])
|