Commit
·
2123ed3
1
Parent(s):
37ff396
Refactor chatbot message handling and formatting
Browse files
app.py
CHANGED
@@ -75,14 +75,15 @@ with gr.Blocks() as demo:
|
|
75 |
|
76 |
def update_chatbot(message, chat_history):
|
77 |
print("Updating chatbot...")
|
78 |
-
#
|
79 |
-
if not chat_history or (chat_history and chat_history[-1][
|
80 |
chat_history = user(message, chat_history)
|
81 |
-
chat_history, _
|
82 |
-
#
|
83 |
formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
|
84 |
return formatted_chat_history, chat_history, ""
|
85 |
|
|
|
86 |
submit.click(
|
87 |
fn=update_chatbot,
|
88 |
inputs=[message, chat_history_state],
|
|
|
75 |
|
76 |
def update_chatbot(message, chat_history):
|
77 |
print("Updating chatbot...")
|
78 |
+
# Ensure the user's message is not added twice
|
79 |
+
if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
|
80 |
chat_history = user(message, chat_history)
|
81 |
+
chat_history, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
|
82 |
+
# Format messages for display, removing roles from content
|
83 |
formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
|
84 |
return formatted_chat_history, chat_history, ""
|
85 |
|
86 |
+
|
87 |
submit.click(
|
88 |
fn=update_chatbot,
|
89 |
inputs=[message, chat_history_state],
|