Commit
·
5a9b18c
1
Parent(s):
c073e36
Refactor chat history formatting logic
Browse files
app.py
CHANGED
@@ -86,12 +86,23 @@ with gr.Blocks() as demo:
|
|
86 |
else:
|
87 |
chat_history = user(message, chat_history)
|
88 |
chat_history, _ = chat(chat_history, system_message, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
|
|
|
89 |
formatted_chat_history = []
|
|
|
90 |
for entry in chat_history:
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
return formatted_chat_history, chat_history, ""
|
96 |
|
97 |
submit.click(
|
|
|
86 |
else:
|
87 |
chat_history = user(message, chat_history)
|
88 |
chat_history, _ = chat(chat_history, system_message, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
|
89 |
+
|
90 |
formatted_chat_history = []
|
91 |
+
last_role = None
|
92 |
for entry in chat_history:
|
93 |
+
role = entry["role"]
|
94 |
+
if role != last_role:
|
95 |
+
if role == "user":
|
96 |
+
formatted_chat_history.append([entry["content"], ""])
|
97 |
+
elif role == "assistant":
|
98 |
+
formatted_chat_history.append(["", entry["content"]])
|
99 |
+
last_role = role
|
100 |
+
else:
|
101 |
+
if role == "user":
|
102 |
+
formatted_chat_history[-1][0] += entry["content"]
|
103 |
+
else:
|
104 |
+
formatted_chat_history[-1][1] += entry["content"]
|
105 |
+
|
106 |
return formatted_chat_history, chat_history, ""
|
107 |
|
108 |
submit.click(
|