Update app.py
Browse files
app.py
CHANGED
|
@@ -546,9 +546,28 @@ def get_recommendation_with_agent(user_id, merchant, category, amount):
|
|
| 546 |
- <60: Suboptimal ❌
|
| 547 |
"""
|
| 548 |
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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 |
-
|
| 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"""
|