add model & temperature option
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def gradio_messages_to_openai_messages(g):
|
|
| 29 |
result.append({"role": "assistant", "content": pair[1]})
|
| 30 |
return result
|
| 31 |
|
| 32 |
-
def respond(chat_history, message, system_message, key_txt, url_txt):
|
| 33 |
messages = [
|
| 34 |
{"role": "system", "content": system_message},
|
| 35 |
*gradio_messages_to_openai_messages(chat_history),
|
|
@@ -40,9 +40,12 @@ def respond(chat_history, message, system_message, key_txt, url_txt):
|
|
| 40 |
openai.api_base = url_txt
|
| 41 |
if DEBUG:
|
| 42 |
print("messages:", messages)
|
|
|
|
|
|
|
| 43 |
completion = openai.ChatCompletion.create(
|
| 44 |
-
model=
|
| 45 |
-
messages=messages
|
|
|
|
| 46 |
)
|
| 47 |
if DEBUG:
|
| 48 |
print("completion:", completion)
|
|
@@ -57,14 +60,15 @@ with gr.Blocks() as demo:
|
|
| 57 |
(", Leave empty to use value from config file" if api_key_from_config else ""))
|
| 58 |
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)
|
| 59 |
system_message = gr.Textbox(label = "System Message:", value = "You are an assistant who gives brief and concise answers.")
|
| 60 |
-
|
|
|
|
| 61 |
with gr.Tab("Chat"):
|
| 62 |
gr.Markdown("## Chat with GPT")
|
| 63 |
chatbot = gr.Chatbot()
|
| 64 |
message = gr.Textbox(label = "Message:", placeholder="Enter text and press 'Send'")
|
| 65 |
message.submit(
|
| 66 |
respond,
|
| 67 |
-
[chatbot, message, system_message, key_txt, url_txt],
|
| 68 |
chatbot,
|
| 69 |
)
|
| 70 |
with gr.Row():
|
|
@@ -73,7 +77,7 @@ with gr.Blocks() as demo:
|
|
| 73 |
send = gr.Button("Send")
|
| 74 |
send.click(
|
| 75 |
respond,
|
| 76 |
-
[chatbot, message, system_message, key_txt, url_txt],
|
| 77 |
chatbot,
|
| 78 |
)
|
| 79 |
|
|
|
|
| 29 |
result.append({"role": "assistant", "content": pair[1]})
|
| 30 |
return result
|
| 31 |
|
| 32 |
+
def respond(chat_history, message, system_message, key_txt, url_txt, model, temperature):
|
| 33 |
messages = [
|
| 34 |
{"role": "system", "content": system_message},
|
| 35 |
*gradio_messages_to_openai_messages(chat_history),
|
|
|
|
| 40 |
openai.api_base = url_txt
|
| 41 |
if DEBUG:
|
| 42 |
print("messages:", messages)
|
| 43 |
+
print("model:", model)
|
| 44 |
+
print("temperature:", temperature)
|
| 45 |
completion = openai.ChatCompletion.create(
|
| 46 |
+
model=model,
|
| 47 |
+
messages=messages,
|
| 48 |
+
temperature=temperature,
|
| 49 |
)
|
| 50 |
if DEBUG:
|
| 51 |
print("completion:", completion)
|
|
|
|
| 60 |
(", Leave empty to use value from config file" if api_key_from_config else ""))
|
| 61 |
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)
|
| 62 |
system_message = gr.Textbox(label = "System Message:", value = "You are an assistant who gives brief and concise answers.")
|
| 63 |
+
model = gr.Dropdown(label="Model", choices=["gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-4"], multiselect=False, value="gpt-3.5-turbo", type="value")
|
| 64 |
+
temperature = gr.Slider(0, 2, value=1, label="Temperature", step=0.1, info="What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.")
|
| 65 |
with gr.Tab("Chat"):
|
| 66 |
gr.Markdown("## Chat with GPT")
|
| 67 |
chatbot = gr.Chatbot()
|
| 68 |
message = gr.Textbox(label = "Message:", placeholder="Enter text and press 'Send'")
|
| 69 |
message.submit(
|
| 70 |
respond,
|
| 71 |
+
[chatbot, message, system_message, key_txt, url_txt, model, temperature],
|
| 72 |
chatbot,
|
| 73 |
)
|
| 74 |
with gr.Row():
|
|
|
|
| 77 |
send = gr.Button("Send")
|
| 78 |
send.click(
|
| 79 |
respond,
|
| 80 |
+
[chatbot, message, system_message, key_txt, url_txt, model, temperature],
|
| 81 |
chatbot,
|
| 82 |
)
|
| 83 |
|