sammy786 commited on
Commit
48132a0
·
verified ·
1 Parent(s): b2f9490

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -546,9 +546,28 @@ def get_recommendation_with_agent(user_id, merchant, category, amount):
546
  - <60: Suboptimal ❌
547
  """
548
 
549
- # Extract key points from reasoning (first 3 sentences or bullet points)
550
- reasoning_lines = reasoning.split('. ')[:3]
551
- reasoning_bullets = '\n'.join([f"- {line.strip()}." for line in reasoning_lines if line.strip()])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
 
553
  output = f"""
554
  ## 🎯 Recommended: **{card_name}**
@@ -579,17 +598,14 @@ def get_recommendation_with_agent(user_id, merchant, category, amount):
579
  alt_card_name = card_name_map.get(alt_card_id, alt_card_id.replace('c_', '').replace('_', ' ').title())
580
  alt_reason = alt.get('reason', 'Good alternative')
581
  alt_reward = alt.get('reward_amount', rewards_earned * 0.8)
582
- # Truncate reason to first sentence
583
- alt_reason_short = (lambda x: x[:60] + '...' if len(x) > 60 else x)(alt_reason.split('.')[0])
584
  output += f"| {alt_card_name} | ${alt_reward:.2f} | {alt_reason_short} |\n"
585
  output += "\n---\n"
586
 
587
  if warnings:
588
  output += "\n### ⚠️ Alerts\n\n"
589
  for warning in warnings:
590
- # Shorten warnings to key info
591
- warning_short = warning[:80] + '...' if len(warning) > 80 else warning
592
- output += f"- {warning_short}\n"
593
  output += "\n---\n"
594
 
595
  output += f"""
 
546
  - <60: Suboptimal ❌
547
  """
548
 
549
+ def format_reasoning(text):
550
+ """Format reasoning text into clean bullet points"""
551
+ # If already has bullet points or numbered lists, use as-is
552
+ if text.strip().startswith(('-', '•', '*', '1.', '2.')):
553
+ return text
554
+
555
+ # Split into sentences
556
+ sentences = text.replace('\n', ' ').split('. ')
557
+
558
+ # Take first 3-4 meaningful sentences
559
+ bullets = []
560
+ for sentence in sentences[:4]:
561
+ sentence = sentence.strip()
562
+ if sentence and len(sentence) > 20: # Skip very short fragments
563
+ # Add period if missing
564
+ if not sentence.endswith('.'):
565
+ sentence += '.'
566
+ bullets.append(f"- {sentence}")
567
+
568
+ return '\n'.join(bullets) if bullets else f"- {text}"
569
+
570
+ reasoning_bullets = format_reasoning(reasoning)
571
 
572
  output = f"""
573
  ## 🎯 Recommended: **{card_name}**
 
598
  alt_card_name = card_name_map.get(alt_card_id, alt_card_id.replace('c_', '').replace('_', ' ').title())
599
  alt_reason = alt.get('reason', 'Good alternative')
600
  alt_reward = alt.get('reward_amount', rewards_earned * 0.8)
601
+ alt_reason_short = alt_reason.split('.')[0].strip() + '.'
 
602
  output += f"| {alt_card_name} | ${alt_reward:.2f} | {alt_reason_short} |\n"
603
  output += "\n---\n"
604
 
605
  if warnings:
606
  output += "\n### ⚠️ Alerts\n\n"
607
  for warning in warnings:
608
+ output += f"- {warning}\n"
 
 
609
  output += "\n---\n"
610
 
611
  output += f"""