Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ client = OpenAI(
|
|
10 |
base_url="https://api.runpod.ai/v2/vllm-k0g4c60zor9xuu/openai/v1",
|
11 |
)
|
12 |
|
13 |
-
def get_response(user_message, history):
|
14 |
# Format the history for the OpenAI call
|
15 |
history_openai_format = []
|
16 |
for human, assistant in history:
|
@@ -20,12 +20,15 @@ def get_response(user_message, history):
|
|
20 |
history_openai_format.append({"role": "assistant", "content": assistant})
|
21 |
history_openai_format.append({"role": "user", "content": user_message})
|
22 |
|
|
|
|
|
|
|
23 |
# Make the API call
|
24 |
response = client.chat.completions.create(
|
25 |
model='ambrosfitz/llama-3-history',
|
26 |
messages=history_openai_format,
|
27 |
-
temperature=
|
28 |
-
max_tokens=
|
29 |
)
|
30 |
|
31 |
# Access the text response
|
@@ -40,17 +43,18 @@ with gr.Blocks() as demo:
|
|
40 |
chatbot = gr.Chatbot()
|
41 |
msg = gr.Textbox()
|
42 |
clear = gr.Button("Clear")
|
|
|
43 |
|
44 |
-
def user(user_message, history):
|
45 |
if not user_message.strip():
|
46 |
return "", history
|
47 |
-
bot_response = get_response(user_message, history)
|
48 |
return "", history + [[user_message, bot_response]]
|
49 |
|
50 |
def clear_chat():
|
51 |
return "", [] # Clear the chat history
|
52 |
|
53 |
-
msg.submit(user, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
54 |
clear.click(clear_chat, inputs=None, outputs=[msg, chatbot])
|
55 |
|
56 |
demo.launch()
|
|
|
10 |
base_url="https://api.runpod.ai/v2/vllm-k0g4c60zor9xuu/openai/v1",
|
11 |
)
|
12 |
|
13 |
+
def get_response(user_message, history, verbosity):
|
14 |
# Format the history for the OpenAI call
|
15 |
history_openai_format = []
|
16 |
for human, assistant in history:
|
|
|
20 |
history_openai_format.append({"role": "assistant", "content": assistant})
|
21 |
history_openai_format.append({"role": "user", "content": user_message})
|
22 |
|
23 |
+
# Adjust the temperature based on the verbosity level
|
24 |
+
temperature = 0.5 if verbosity == "Balanced" else 0.3 if verbosity == "Concise" else 0.7
|
25 |
+
|
26 |
# Make the API call
|
27 |
response = client.chat.completions.create(
|
28 |
model='ambrosfitz/llama-3-history',
|
29 |
messages=history_openai_format,
|
30 |
+
temperature=temperature,
|
31 |
+
max_tokens=150
|
32 |
)
|
33 |
|
34 |
# Access the text response
|
|
|
43 |
chatbot = gr.Chatbot()
|
44 |
msg = gr.Textbox()
|
45 |
clear = gr.Button("Clear")
|
46 |
+
verbosity = gr.Radio(["Concise", "Balanced", "Detailed"], value="Balanced", label="Verbosity")
|
47 |
|
48 |
+
def user(user_message, history, verbosity):
|
49 |
if not user_message.strip():
|
50 |
return "", history
|
51 |
+
bot_response = get_response(user_message, history, verbosity)
|
52 |
return "", history + [[user_message, bot_response]]
|
53 |
|
54 |
def clear_chat():
|
55 |
return "", [] # Clear the chat history
|
56 |
|
57 |
+
msg.submit(user, inputs=[msg, chatbot, verbosity], outputs=[msg, chatbot])
|
58 |
clear.click(clear_chat, inputs=None, outputs=[msg, chatbot])
|
59 |
|
60 |
demo.launch()
|