minhvtt commited on
Commit
97c403c
verified
1 Parent(s): d52b84f

Update agent_service.py

Browse files
Files changed (1) hide show
  1. agent_service.py +19 -2
agent_service.py CHANGED
@@ -471,15 +471,32 @@ class AgentService:
471
  formatted = []
472
  for i, result in enumerate(final_results[:5], 1): # Limit to top 5
473
  payload = result.get("payload", {})
 
 
 
 
 
 
 
 
474
  texts = payload.get("texts", [])
475
- text = texts[0] if texts else ""
 
 
 
 
 
 
 
 
476
  event_id = payload.get("id_use", "")
477
 
478
  if not text:
 
479
  continue
480
 
481
  # Clean and truncate text for context window
482
- clean_text = text.replace("\n", " ").strip()
483
  formatted.append(f"Event Found: {clean_text[:300]}... (ID: {event_id})")
484
 
485
  if not formatted:
 
471
  formatted = []
472
  for i, result in enumerate(final_results[:5], 1): # Limit to top 5
473
  payload = result.get("payload", {})
474
+
475
+ # DEBUG: Log payload keys for first result
476
+ if i == 1:
477
+ print(f"馃悰 First Result Payload Keys: {list(payload.keys())}")
478
+ if 'texts' not in payload and 'text' in payload:
479
+ print(f"鈿狅笍 Found 'text' but not 'texts'. Using 'text' field.")
480
+
481
+ # Robust extraction of text content
482
  texts = payload.get("texts", [])
483
+ if isinstance(texts, list) and texts:
484
+ text = texts[0] # List of chunks
485
+ elif isinstance(texts, str):
486
+ text = texts # Single string
487
+ elif 'text' in payload:
488
+ text = payload.get('text') # Fallback to 'text' field
489
+ else:
490
+ text = ""
491
+
492
  event_id = payload.get("id_use", "")
493
 
494
  if not text:
495
+ print(f"鈿狅笍 Result {i} skipped: Empty text content. ID: {event_id}")
496
  continue
497
 
498
  # Clean and truncate text for context window
499
+ clean_text = str(text).replace("\n", " ").strip()
500
  formatted.append(f"Event Found: {clean_text[:300]}... (ID: {event_id})")
501
 
502
  if not formatted: