VietCat commited on
Commit
0b04c0a
·
1 Parent(s): e2d0ed8

fix search result

Browse files
Files changed (1) hide show
  1. app/main.py +27 -8
app/main.py CHANGED
@@ -106,7 +106,6 @@ async def webhook(request: Request):
106
 
107
  try:
108
  body = json.loads(body_bytes)
109
- logger.info(f"[DEBUG] body: {body}")
110
  # Kiểm tra an toàn echo
111
  is_echo = (
112
  isinstance(body, dict)
@@ -272,13 +271,33 @@ async def process_message(message_data: Dict[str, Any]):
272
  def format_search_results(matches: List[Dict[str, Any]]) -> str:
273
  if not matches:
274
  return "Không tìm thấy kết quả phù hợp."
275
- result = "Đây một số kết quả phù hợp:\n\n"
276
- for i, match in enumerate(matches, 1):
277
- result += f"{i}. {match['content']}\n"
278
- if match.get('metadata', {}).get('url'):
279
- result += f" Link: {match['metadata']['url']}\n"
280
- result += "\n"
281
- return result.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
 
283
  async def create_facebook_post(page_token: str, sender_id: str, history: List[Dict[str, Any]]) -> str:
284
  """
 
106
 
107
  try:
108
  body = json.loads(body_bytes)
 
109
  # Kiểm tra an toàn echo
110
  is_echo = (
111
  isinstance(body, dict)
 
271
  def format_search_results(matches: List[Dict[str, Any]]) -> str:
272
  if not matches:
273
  return "Không tìm thấy kết quả phù hợp."
274
+ # Tìm item similarity cao nhất
275
+ top = None
276
+ for item in matches:
277
+ if not top or (item.get('similarity', 0) > top.get('similarity', 0)):
278
+ top = item
279
+ result_text = ""
280
+ if top and (top.get('tieude') or top.get('noidung')):
281
+ # Thực hiện hành vi
282
+ tieude = (top.get('tieude') or '').strip()
283
+ noidung = (top.get('noidung') or '').strip()
284
+ hanhvi = (tieude + "\n" + noidung).strip().replace('\n', ' ')
285
+ result_text += f"Thực hiện hành vi:\n{hanhvi}"
286
+ # Cá nhân bị phạt tiền
287
+ if top.get('canhantu') or top.get('canhanden'):
288
+ result_text += f"\nCá nhân sẽ bị phạt tiền từ {top.get('canhantu', '')} VNĐ đến {top.get('canhanden', '')} VNĐ"
289
+ # Tổ chức bị phạt tiền
290
+ if top.get('tochuctu') or top.get('tochucden'):
291
+ result_text += f"\nTổ chức sẽ bị phạt tiền từ {top.get('tochuctu', '')} VNĐ đến {top.get('tochucden', '')} VNĐ"
292
+ # Hình phạt bổ sung
293
+ if top.get('hpbsnoidung'):
294
+ result_text += f"\nNgoài việc bị phạt tiền, người vi phạm còn bị {top.get('hpbsnoidung')}"
295
+ # Biện pháp khắc phục hậu quả
296
+ if top.get('bpkpnoidung'):
297
+ result_text += f"\nNgoài ra, người vi phạm còn bị buộc {top.get('bpkpnoidung')}"
298
+ else:
299
+ result_text = "Không có kết quả phù hợp!"
300
+ return result_text.strip()
301
 
302
  async def create_facebook_post(page_token: str, sender_id: str, history: List[Dict[str, Any]]) -> str:
303
  """