add tab
Browse files
app.py
CHANGED
@@ -36,39 +36,44 @@ def respond(chat_history, message, system_message, key_txt, url_txt):
|
|
36 |
openai.api_key = key_txt if key_txt else api_key_from_config
|
37 |
if url_txt:
|
38 |
openai.api_base = url_txt
|
|
|
|
|
39 |
completion = openai.ChatCompletion.create(
|
40 |
model="gpt-3.5-turbo",
|
41 |
messages=messages
|
42 |
)
|
43 |
if DEBUG:
|
44 |
-
print("messages:", messages)
|
45 |
print("completion:", completion)
|
46 |
response = completion['choices'][0]['message']['content']
|
47 |
result = chat_history + [[message, response]]
|
48 |
return result
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
-
gr.
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
)
|
64 |
-
with gr.Row():
|
65 |
-
clear = gr.Button("Clear")
|
66 |
-
clear.click(lambda: None, None, chatbot)
|
67 |
-
send = gr.Button("Send")
|
68 |
-
send.click(
|
69 |
respond,
|
70 |
[chatbot, message, system_message, key_txt, url_txt],
|
71 |
chatbot,
|
72 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
demo.launch(server_name=server_name, server_port=server_port)
|
|
|
36 |
openai.api_key = key_txt if key_txt else api_key_from_config
|
37 |
if url_txt:
|
38 |
openai.api_base = url_txt
|
39 |
+
if DEBUG:
|
40 |
+
print("messages:", messages)
|
41 |
completion = openai.ChatCompletion.create(
|
42 |
model="gpt-3.5-turbo",
|
43 |
messages=messages
|
44 |
)
|
45 |
if DEBUG:
|
|
|
46 |
print("completion:", completion)
|
47 |
response = completion['choices'][0]['message']['content']
|
48 |
result = chat_history + [[message, response]]
|
49 |
return result
|
50 |
|
51 |
with gr.Blocks() as demo:
|
52 |
+
with gr.Tab("Config"):
|
53 |
+
with gr.Row():
|
54 |
+
key_txt = gr.Textbox(label = "Openai Key", placeholder="Enter openai key 'sk-xxxx'%s" %
|
55 |
+
(", Leave empty to use value from config file" if not openai.api_key else ""))
|
56 |
+
url_txt = gr.Textbox(label = "Openai API Base URL", placeholder="Enter openai base url 'https://xxx', Leave empty to use value '%s'" % openai.api_base)
|
57 |
+
system_message = gr.Textbox(label = "System Message:", value = "You are an assistant who gives brief and concise answers.")
|
58 |
+
|
59 |
+
with gr.Tab("Chat"):
|
60 |
+
gr.Markdown("## Chat with GPT")
|
61 |
+
chatbot = gr.Chatbot()
|
62 |
+
message = gr.Textbox(label = "Message:", placeholder="Enter text and press 'Send'")
|
63 |
+
message.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
respond,
|
65 |
[chatbot, message, system_message, key_txt, url_txt],
|
66 |
chatbot,
|
67 |
)
|
68 |
+
with gr.Row():
|
69 |
+
clear = gr.Button("Clear")
|
70 |
+
clear.click(lambda: None, None, chatbot)
|
71 |
+
send = gr.Button("Send")
|
72 |
+
send.click(
|
73 |
+
respond,
|
74 |
+
[chatbot, message, system_message, key_txt, url_txt],
|
75 |
+
chatbot,
|
76 |
+
)
|
77 |
+
|
78 |
|
79 |
demo.launch(server_name=server_name, server_port=server_port)
|