add quota manager
Browse files- app/main.py +6 -3
app/main.py
CHANGED
|
@@ -312,7 +312,7 @@ async def process_message(message_data: Dict[str, Any]):
|
|
| 312 |
|
| 313 |
logger.info(f"[DEBUG] Phương tiện: {keywords} - Hành vi: {hanh_vi_vi_pham} - Mục đích: {muc_dich}")
|
| 314 |
|
| 315 |
-
await facebook_client.send_message(page_token, sender_id, "
|
| 316 |
|
| 317 |
# 4. Update lại conversation với thông tin đầy đủ
|
| 318 |
update_kwargs = {
|
|
@@ -365,7 +365,7 @@ async def process_business_logic(log_kwargs: Dict[str, Any], page_token: str) ->
|
|
| 365 |
matches = supabase_client.match_documents(embedding, vehicle_keywords=keywords)
|
| 366 |
logger.info(f"[DEBUG] matches: {matches}")
|
| 367 |
if matches:
|
| 368 |
-
response = await format_search_results(message, matches)
|
| 369 |
else:
|
| 370 |
response = "Xin lỗi, tôi không tìm thấy thông tin phù hợp."
|
| 371 |
else:
|
|
@@ -394,9 +394,11 @@ async def process_business_logic(log_kwargs: Dict[str, Any], page_token: str) ->
|
|
| 394 |
|
| 395 |
return response
|
| 396 |
|
| 397 |
-
async def format_search_results(question: str, matches: List[Dict[str, Any]]) -> str:
|
| 398 |
if not matches:
|
| 399 |
return "Không tìm thấy kết quả phù hợp."
|
|
|
|
|
|
|
| 400 |
# Rerank matches trước khi format cho LLM
|
| 401 |
try:
|
| 402 |
reranked = await reranker.rerank(question, matches, top_k=5)
|
|
@@ -475,6 +477,7 @@ async def format_search_results(question: str, matches: List[Dict[str, Any]]) ->
|
|
| 475 |
f"\n\nCâu hỏi của người dùng: {question}\n"
|
| 476 |
)
|
| 477 |
|
|
|
|
| 478 |
# Gọi LLM để sinh câu trả lời, fallback nếu lỗi
|
| 479 |
try:
|
| 480 |
answer = await llm_client.generate_text(prompt)
|
|
|
|
| 312 |
|
| 313 |
logger.info(f"[DEBUG] Phương tiện: {keywords} - Hành vi: {hanh_vi_vi_pham} - Mục đích: {muc_dich}")
|
| 314 |
|
| 315 |
+
await facebook_client.send_message(page_token, sender_id, f"... đang tìm kiếm hành vi {hanh_vi_vi_pham} .....")
|
| 316 |
|
| 317 |
# 4. Update lại conversation với thông tin đầy đủ
|
| 318 |
update_kwargs = {
|
|
|
|
| 365 |
matches = supabase_client.match_documents(embedding, vehicle_keywords=keywords)
|
| 366 |
logger.info(f"[DEBUG] matches: {matches}")
|
| 367 |
if matches:
|
| 368 |
+
response = await format_search_results(message, matches, page_token, log_kwargs['recipient_id'])
|
| 369 |
else:
|
| 370 |
response = "Xin lỗi, tôi không tìm thấy thông tin phù hợp."
|
| 371 |
else:
|
|
|
|
| 394 |
|
| 395 |
return response
|
| 396 |
|
| 397 |
+
async def format_search_results(question: str, matches: List[Dict[str, Any]], page_token: str, sender_id: str) -> str:
|
| 398 |
if not matches:
|
| 399 |
return "Không tìm thấy kết quả phù hợp."
|
| 400 |
+
|
| 401 |
+
await facebook_client.send_message(page_token, sender_id, f"Tôi tìm thấy một số quy định rồi .....")
|
| 402 |
# Rerank matches trước khi format cho LLM
|
| 403 |
try:
|
| 404 |
reranked = await reranker.rerank(question, matches, top_k=5)
|
|
|
|
| 477 |
f"\n\nCâu hỏi của người dùng: {question}\n"
|
| 478 |
)
|
| 479 |
|
| 480 |
+
await facebook_client.send_message(page_token, sender_id, f"Được rồi, để tôi tóm tắt lại nhé .....")
|
| 481 |
# Gọi LLM để sinh câu trả lời, fallback nếu lỗi
|
| 482 |
try:
|
| 483 |
answer = await llm_client.generate_text(prompt)
|