Commit
·
dfe0ed3
1
Parent(s):
e185930
Fix average_expense to use user-provided budget_amount and enhance OpenAI prompt to recommend decrease when budget is too high
Browse files- app/smart_recommendation.py +20 -6
app/smart_recommendation.py
CHANGED
|
@@ -374,6 +374,7 @@ class SmartBudgetRecommender:
|
|
| 374 |
category_name = self._get_category_name(actual_category_id)
|
| 375 |
|
| 376 |
# PRIORITY: Use provided budget_amount if available, otherwise use budget's maxAmount
|
|
|
|
| 377 |
if budget_amount is None or budget_amount <= 0:
|
| 378 |
budget_max_amount = float(budget_by_id.get("maxAmount", 0) or 0)
|
| 379 |
budget_spend_amount = float(budget_by_id.get("spendAmount", 0) or 0)
|
|
@@ -381,7 +382,8 @@ class SmartBudgetRecommender:
|
|
| 381 |
|
| 382 |
# If we have a valid budget amount, generate recommendation
|
| 383 |
if budget_amount and budget_amount > 0:
|
| 384 |
-
#
|
|
|
|
| 385 |
avg_expense = budget_amount
|
| 386 |
monthly_values = [avg_expense]
|
| 387 |
std_dev = avg_expense * 0.05
|
|
@@ -1445,19 +1447,31 @@ class SmartBudgetRecommender:
|
|
| 1445 |
f"💰 USER'S BUDGET AMOUNT: The user has SET/PLANNED a budget of {avg_expense:,.2f} for this category.\n"
|
| 1446 |
f"This is the budget amount the user wants to allocate - this is the ONLY data point available.\n"
|
| 1447 |
f"There is NO spending history to analyze - this is a fresh budget.\n\n"
|
| 1448 |
-
f"🎯 YOUR TASK: Provide
|
| 1449 |
f"Your recommendation should be based on:\n"
|
| 1450 |
f" 1. The user's provided budget amount: {avg_expense:,.2f} (this is what they want to set)\n"
|
| 1451 |
f" 2. Category-specific knowledge (e.g., Food & Drinks inflation, Transport volatility)\n"
|
| 1452 |
f" 3. General best practices (add 10-15% buffer for new budgets to account for variability)\n"
|
| 1453 |
f" 4. Economic factors (inflation typically 2-5% annually, category-specific inflation)\n\n"
|
| 1454 |
f"💡 KEY INSIGHT: The user has indicated they want to budget {avg_expense:,.2f} for this category.\n"
|
| 1455 |
-
f" -
|
| 1456 |
-
f"
|
| 1457 |
-
f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1458 |
f"DO NOT reference fake trends or historical patterns - this is a new budget!\n"
|
| 1459 |
f"Recommend a budget that accounts for typical variability and inflation for this category.\n"
|
| 1460 |
-
f"For new budgets, typically recommend 10-15% increase from the user's provided amount to create a safety buffer.\n"
|
| 1461 |
)
|
| 1462 |
else:
|
| 1463 |
# This is based on real historical data
|
|
|
|
| 374 |
category_name = self._get_category_name(actual_category_id)
|
| 375 |
|
| 376 |
# PRIORITY: Use provided budget_amount if available, otherwise use budget's maxAmount
|
| 377 |
+
# IMPORTANT: If user provided budget_amount, use it as the base for recommendation
|
| 378 |
if budget_amount is None or budget_amount <= 0:
|
| 379 |
budget_max_amount = float(budget_by_id.get("maxAmount", 0) or 0)
|
| 380 |
budget_spend_amount = float(budget_by_id.get("spendAmount", 0) or 0)
|
|
|
|
| 382 |
|
| 383 |
# If we have a valid budget amount, generate recommendation
|
| 384 |
if budget_amount and budget_amount > 0:
|
| 385 |
+
# CRITICAL: Use the provided budget_amount as average_expense
|
| 386 |
+
# This is what the user wants to set, so recommendations should be based on this
|
| 387 |
avg_expense = budget_amount
|
| 388 |
monthly_values = [avg_expense]
|
| 389 |
std_dev = avg_expense * 0.05
|
|
|
|
| 1447 |
f"💰 USER'S BUDGET AMOUNT: The user has SET/PLANNED a budget of {avg_expense:,.2f} for this category.\n"
|
| 1448 |
f"This is the budget amount the user wants to allocate - this is the ONLY data point available.\n"
|
| 1449 |
f"There is NO spending history to analyze - this is a fresh budget.\n\n"
|
| 1450 |
+
f"🎯 YOUR TASK: Provide an INTELLIGENT recommendation based on the user's budget amount of {avg_expense:,.2f}\n\n"
|
| 1451 |
f"Your recommendation should be based on:\n"
|
| 1452 |
f" 1. The user's provided budget amount: {avg_expense:,.2f} (this is what they want to set)\n"
|
| 1453 |
f" 2. Category-specific knowledge (e.g., Food & Drinks inflation, Transport volatility)\n"
|
| 1454 |
f" 3. General best practices (add 10-15% buffer for new budgets to account for variability)\n"
|
| 1455 |
f" 4. Economic factors (inflation typically 2-5% annually, category-specific inflation)\n\n"
|
| 1456 |
f"💡 KEY INSIGHT: The user has indicated they want to budget {avg_expense:,.2f} for this category.\n"
|
| 1457 |
+
f" - ANALYZE if this amount is REASONABLE for the category:\n"
|
| 1458 |
+
f" * If the amount seems TOO LOW for the category → Recommend INCREASE (10-20%)\n"
|
| 1459 |
+
f" * If the amount seems TOO HIGH for the category → Recommend DECREASE (10-20%)\n"
|
| 1460 |
+
f" * If the amount seems REASONABLE → Recommend KEEP or small increase (5-10% buffer)\n"
|
| 1461 |
+
f" - Consider category-specific factors:\n"
|
| 1462 |
+
f" * Food & Drinks: Typically needs 10-15% buffer for inflation and variability\n"
|
| 1463 |
+
f" * Transport: May need 15-20% buffer due to fuel price volatility\n"
|
| 1464 |
+
f" * Entertainment: May need less buffer (5-10%) if amount is reasonable\n"
|
| 1465 |
+
f" * Utilities: Usually stable, 5-10% buffer is sufficient\n"
|
| 1466 |
+
f" - Use your knowledge about typical spending ranges for this category\n"
|
| 1467 |
+
f" - If user's amount is clearly excessive for the category, recommend DECREASE\n"
|
| 1468 |
+
f" - If user's amount is clearly insufficient, recommend INCREASE\n\n"
|
| 1469 |
+
f"🚨 CRITICAL: DO NOT ALWAYS RECOMMEND INCREASE!\n"
|
| 1470 |
+
f" - If the user's budget amount ({avg_expense:,.2f}) is already generous for {category}, recommend DECREASE\n"
|
| 1471 |
+
f" - If the amount is reasonable, recommend KEEP with small buffer (5-10%)\n"
|
| 1472 |
+
f" - Only recommend INCREASE if the amount seems insufficient for the category\n\n"
|
| 1473 |
f"DO NOT reference fake trends or historical patterns - this is a new budget!\n"
|
| 1474 |
f"Recommend a budget that accounts for typical variability and inflation for this category.\n"
|
|
|
|
| 1475 |
)
|
| 1476 |
else:
|
| 1477 |
# This is based on real historical data
|