make each round of chat colorful
Browse files
app.py
CHANGED
@@ -267,11 +267,38 @@ def chat_with_models(
|
|
267 |
elif model_response["error"]:
|
268 |
raise Exception(model_response["error"])
|
269 |
else:
|
270 |
-
|
271 |
conversation_state[model_name].append(
|
272 |
{"role": "assistant", "content": model_response["content"]}
|
273 |
)
|
274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
|
277 |
def save_content_to_hf(feedback_data, repo_name):
|
|
|
267 |
elif model_response["error"]:
|
268 |
raise Exception(model_response["error"])
|
269 |
else:
|
270 |
+
# Add the model's response to the conversation state
|
271 |
conversation_state[model_name].append(
|
272 |
{"role": "assistant", "content": model_response["content"]}
|
273 |
)
|
274 |
+
|
275 |
+
# Format the complete conversation history with different colors
|
276 |
+
formatted_history = format_conversation_history(conversation_state[model_name])
|
277 |
+
|
278 |
+
return formatted_history
|
279 |
+
|
280 |
+
|
281 |
+
def format_conversation_history(conversation_history):
|
282 |
+
"""
|
283 |
+
Format the conversation history with different colors for user and model messages.
|
284 |
+
|
285 |
+
Args:
|
286 |
+
conversation_history (list): List of conversation messages with role and content.
|
287 |
+
|
288 |
+
Returns:
|
289 |
+
str: Markdown formatted conversation history.
|
290 |
+
"""
|
291 |
+
formatted_text = ""
|
292 |
+
|
293 |
+
for message in conversation_history:
|
294 |
+
if message["role"] == "user":
|
295 |
+
# Format user messages with blue text
|
296 |
+
formatted_text += f"<div style='color: #0066cc; background-color: #f0f7ff; padding: 10px; border-radius: 5px; margin-bottom: 10px;'><strong>User:</strong> {message['content']}</div>\n\n"
|
297 |
+
else: # assistant/model messages
|
298 |
+
# Format model messages with dark green text
|
299 |
+
formatted_text += f"<div style='color: #006633; background-color: #f0fff0; padding: 10px; border-radius: 5px; margin-bottom: 10px;'><strong>Model:</strong> {message['content']}</div>\n\n"
|
300 |
+
|
301 |
+
return formatted_text
|
302 |
|
303 |
|
304 |
def save_content_to_hf(feedback_data, repo_name):
|