Spaces:
Sleeping
Sleeping
Thêm author để custom avatar
Browse files
app.py
CHANGED
|
@@ -287,16 +287,20 @@ class UIService:
|
|
| 287 |
]
|
| 288 |
|
| 289 |
@staticmethod
|
| 290 |
-
async def send_message_with_buttons(content: str, actions=None):
|
| 291 |
-
"""Send message with optional action buttons"""
|
| 292 |
if actions is None:
|
| 293 |
actions = UIService.create_action_buttons()
|
| 294 |
-
await cl.Message(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
@staticmethod
|
| 297 |
async def create_typing_animation():
|
| 298 |
"""Create typing animation effect"""
|
| 299 |
-
msg = cl.Message(content="")
|
| 300 |
await msg.send()
|
| 301 |
|
| 302 |
# Typing animation frames
|
|
@@ -320,33 +324,38 @@ async def on_chat_start():
|
|
| 320 |
"""Initialize the chat session"""
|
| 321 |
await StateManager.clear_chat_state(app_state)
|
| 322 |
await cl.Message(
|
| 323 |
-
content="🛍️ **RangDong Sales Agent**\n\nXin chào! Tôi có thể giúp bạn tìm kiếm và tư vấn sản phẩm RangDong. Hãy thử các câu hỏi mẫu:\n\n- Tìm sản phẩm bình giữ nhiệt dung tích dưới 2 lít\n- Tìm sản phẩm ổ cắm thông minh\n- Tư vấn cho tôi đèn học chống cận cho con gái của tôi học lớp 6"
|
|
|
|
| 324 |
).send()
|
| 325 |
|
| 326 |
# Create initial action buttons
|
| 327 |
actions = UIService.create_action_buttons()
|
| 328 |
-
await cl.Message(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
|
| 331 |
@cl.action_callback("show_specs")
|
| 332 |
async def on_show_specs(action):
|
| 333 |
"""Handle show specifications action"""
|
| 334 |
specs_content = DisplayService.show_specs(app_state)
|
| 335 |
-
await UIService.send_message_with_buttons(specs_content)
|
| 336 |
|
| 337 |
|
| 338 |
@cl.action_callback("show_advantages")
|
| 339 |
async def on_show_advantages(action):
|
| 340 |
"""Handle show advantages action"""
|
| 341 |
adv_content = DisplayService.show_advantages(app_state)
|
| 342 |
-
await UIService.send_message_with_buttons(adv_content)
|
| 343 |
|
| 344 |
|
| 345 |
@cl.action_callback("show_packages")
|
| 346 |
async def on_show_packages(action):
|
| 347 |
"""Handle show packages action"""
|
| 348 |
pkg_content = DisplayService.show_solution_packages(app_state)
|
| 349 |
-
await UIService.send_message_with_buttons(pkg_content)
|
| 350 |
|
| 351 |
|
| 352 |
@cl.action_callback("change_model")
|
|
@@ -367,7 +376,8 @@ async def on_change_model(action):
|
|
| 367 |
|
| 368 |
await cl.Message(
|
| 369 |
content=f"**Model hiện tại**: {app_state.selected_model}\n\nChọn model mới:",
|
| 370 |
-
actions=model_actions
|
|
|
|
| 371 |
).send()
|
| 372 |
|
| 373 |
|
|
@@ -375,25 +385,29 @@ async def on_change_model(action):
|
|
| 375 |
async def on_back_to_main(action):
|
| 376 |
"""Handle back to main menu action"""
|
| 377 |
actions = UIService.create_action_buttons()
|
| 378 |
-
await cl.Message(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
|
| 381 |
@cl.action_callback("select_model_0")
|
| 382 |
async def on_select_model_0(action):
|
| 383 |
StateManager.change_model(app_state, "Gemini 2.0 Flash")
|
| 384 |
-
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.0 Flash**")
|
| 385 |
|
| 386 |
|
| 387 |
@cl.action_callback("select_model_1")
|
| 388 |
async def on_select_model_1(action):
|
| 389 |
StateManager.change_model(app_state, "Gemini 2.5 Flash Lite")
|
| 390 |
-
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.5 Flash Lite**")
|
| 391 |
|
| 392 |
|
| 393 |
@cl.action_callback("select_model_2")
|
| 394 |
async def on_select_model_2(action):
|
| 395 |
StateManager.change_model(app_state, "Gemini 2.0 Flash Lite")
|
| 396 |
-
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.0 Flash Lite**")
|
| 397 |
|
| 398 |
|
| 399 |
@cl.on_message
|
|
@@ -416,4 +430,5 @@ async def main(message: cl.Message):
|
|
| 416 |
# Update the typing message with final response and buttons
|
| 417 |
typing_msg.content = response
|
| 418 |
typing_msg.actions = UIService.create_action_buttons()
|
|
|
|
| 419 |
await typing_msg.update()
|
|
|
|
| 287 |
]
|
| 288 |
|
| 289 |
@staticmethod
|
| 290 |
+
async def send_message_with_buttons(content: str, actions=None, author="assistant"):
|
| 291 |
+
"""Send message with optional action buttons and author"""
|
| 292 |
if actions is None:
|
| 293 |
actions = UIService.create_action_buttons()
|
| 294 |
+
await cl.Message(
|
| 295 |
+
content=content,
|
| 296 |
+
actions=actions,
|
| 297 |
+
author=author
|
| 298 |
+
).send()
|
| 299 |
|
| 300 |
@staticmethod
|
| 301 |
async def create_typing_animation():
|
| 302 |
"""Create typing animation effect"""
|
| 303 |
+
msg = cl.Message(content="", author="assistant")
|
| 304 |
await msg.send()
|
| 305 |
|
| 306 |
# Typing animation frames
|
|
|
|
| 324 |
"""Initialize the chat session"""
|
| 325 |
await StateManager.clear_chat_state(app_state)
|
| 326 |
await cl.Message(
|
| 327 |
+
content="🛍️ **RangDong Sales Agent**\n\nXin chào! Tôi có thể giúp bạn tìm kiếm và tư vấn sản phẩm RangDong. Hãy thử các câu hỏi mẫu:\n\n- Tìm sản phẩm bình giữ nhiệt dung tích dưới 2 lít\n- Tìm sản phẩm ổ cắm thông minh\n- Tư vấn cho tôi đèn học chống cận cho con gái của tôi học lớp 6",
|
| 328 |
+
author="assistant"
|
| 329 |
).send()
|
| 330 |
|
| 331 |
# Create initial action buttons
|
| 332 |
actions = UIService.create_action_buttons()
|
| 333 |
+
await cl.Message(
|
| 334 |
+
content="Sử dụng các nút bên dưới để:",
|
| 335 |
+
actions=actions,
|
| 336 |
+
author="assistant"
|
| 337 |
+
).send()
|
| 338 |
|
| 339 |
|
| 340 |
@cl.action_callback("show_specs")
|
| 341 |
async def on_show_specs(action):
|
| 342 |
"""Handle show specifications action"""
|
| 343 |
specs_content = DisplayService.show_specs(app_state)
|
| 344 |
+
await UIService.send_message_with_buttons(specs_content, author="assistant")
|
| 345 |
|
| 346 |
|
| 347 |
@cl.action_callback("show_advantages")
|
| 348 |
async def on_show_advantages(action):
|
| 349 |
"""Handle show advantages action"""
|
| 350 |
adv_content = DisplayService.show_advantages(app_state)
|
| 351 |
+
await UIService.send_message_with_buttons(adv_content, author="assistant")
|
| 352 |
|
| 353 |
|
| 354 |
@cl.action_callback("show_packages")
|
| 355 |
async def on_show_packages(action):
|
| 356 |
"""Handle show packages action"""
|
| 357 |
pkg_content = DisplayService.show_solution_packages(app_state)
|
| 358 |
+
await UIService.send_message_with_buttons(pkg_content, author="assistant")
|
| 359 |
|
| 360 |
|
| 361 |
@cl.action_callback("change_model")
|
|
|
|
| 376 |
|
| 377 |
await cl.Message(
|
| 378 |
content=f"**Model hiện tại**: {app_state.selected_model}\n\nChọn model mới:",
|
| 379 |
+
actions=model_actions,
|
| 380 |
+
author="assistant"
|
| 381 |
).send()
|
| 382 |
|
| 383 |
|
|
|
|
| 385 |
async def on_back_to_main(action):
|
| 386 |
"""Handle back to main menu action"""
|
| 387 |
actions = UIService.create_action_buttons()
|
| 388 |
+
await cl.Message(
|
| 389 |
+
content="📋 **Menu chính**\n\nSử dụng các nút bên dưới để:",
|
| 390 |
+
actions=actions,
|
| 391 |
+
author="assistant"
|
| 392 |
+
).send()
|
| 393 |
|
| 394 |
|
| 395 |
@cl.action_callback("select_model_0")
|
| 396 |
async def on_select_model_0(action):
|
| 397 |
StateManager.change_model(app_state, "Gemini 2.0 Flash")
|
| 398 |
+
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.0 Flash**", author="assistant")
|
| 399 |
|
| 400 |
|
| 401 |
@cl.action_callback("select_model_1")
|
| 402 |
async def on_select_model_1(action):
|
| 403 |
StateManager.change_model(app_state, "Gemini 2.5 Flash Lite")
|
| 404 |
+
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.5 Flash Lite**", author="assistant")
|
| 405 |
|
| 406 |
|
| 407 |
@cl.action_callback("select_model_2")
|
| 408 |
async def on_select_model_2(action):
|
| 409 |
StateManager.change_model(app_state, "Gemini 2.0 Flash Lite")
|
| 410 |
+
await UIService.send_message_with_buttons("✅ Đã chuyển sang **Gemini 2.0 Flash Lite**", author="assistant")
|
| 411 |
|
| 412 |
|
| 413 |
@cl.on_message
|
|
|
|
| 430 |
# Update the typing message with final response and buttons
|
| 431 |
typing_msg.content = response
|
| 432 |
typing_msg.actions = UIService.create_action_buttons()
|
| 433 |
+
typing_msg.author = "assistant" # Ensure author is set
|
| 434 |
await typing_msg.update()
|