LogicGoInfotechSpaces commited on
Commit
f26b6aa
·
1 Parent(s): 94062ea

Remove simulated data creation - recommendations for new budgets now based on provided budget_amount and category knowledge only, not fake trends

Browse files
Files changed (2) hide show
  1. app/main.py +14 -5
  2. app/smart_recommendation.py +41 -47
app/main.py CHANGED
@@ -219,11 +219,20 @@ async def check_and_get_recommendations(request: RecommendationRequest, month: O
219
  )
220
 
221
  if recommendations:
222
- return RecommendationResponse(
223
- has_previous_data=True,
224
- recommendations=recommendations,
225
- message=None
226
- )
 
 
 
 
 
 
 
 
 
227
  else:
228
  # User has data but no recommendations generated (edge case)
229
  return RecommendationResponse(
 
219
  )
220
 
221
  if recommendations:
222
+ # Check if this is based on budget_amount only (no real historical data)
223
+ # If user doesn't have data but provided budget_amount, set has_previous_data=False
224
+ if not has_data and request.budget_amount:
225
+ return RecommendationResponse(
226
+ has_previous_data=False,
227
+ recommendations=recommendations,
228
+ message="Recommendation generated based on provided budget amount. User does not have previous spending data for this category."
229
+ )
230
+ else:
231
+ return RecommendationResponse(
232
+ has_previous_data=True,
233
+ recommendations=recommendations,
234
+ message=None
235
+ )
236
  else:
237
  # User has data but no recommendations generated (edge case)
238
  return RecommendationResponse(
app/smart_recommendation.py CHANGED
@@ -377,44 +377,17 @@ class SmartBudgetRecommender:
377
  # Generate recommendation
378
  print(f"🔍 get_recommendation_for_category: Generating recommendation for category_name={category_name}, avg_expense={avg_expense}")
379
 
380
- # If we only have budget_amount (no historical data), create simulated variation
381
- # to help OpenAI make better recommendations based on category type
382
  if using_budget_amount_only:
383
- # Create simulated monthly values with realistic variation based on category
384
- # This helps OpenAI understand spending patterns and make smarter recommendations
385
- if "food" in category_name.lower() or "groceries" in category_name.lower() or "drinks" in category_name.lower():
386
- # Food categories tend to have moderate variation
387
- monthly_values = [
388
- avg_expense * 0.92,
389
- avg_expense * 0.96,
390
- avg_expense,
391
- avg_expense * 1.04,
392
- avg_expense * 1.08,
393
- ]
394
- elif "transport" in category_name.lower() or "travel" in category_name.lower():
395
- # Transport can vary more
396
- monthly_values = [
397
- avg_expense * 0.85,
398
- avg_expense * 0.95,
399
- avg_expense,
400
- avg_expense * 1.10,
401
- avg_expense * 1.15,
402
- ]
403
- else:
404
- # Default: moderate variation
405
- monthly_values = [
406
- avg_expense * 0.90,
407
- avg_expense * 0.95,
408
- avg_expense,
409
- avg_expense * 1.05,
410
- avg_expense * 1.10,
411
- ]
412
-
413
- # Calculate std_dev from simulated values
414
- mean = sum(monthly_values) / len(monthly_values)
415
- variance = sum((x - mean) ** 2 for x in monthly_values) / len(monthly_values)
416
- std_dev = variance ** 0.5
417
- months_analyzed = len(monthly_values)
418
  else:
419
  monthly_values = data.get("monthly_values", [avg_expense])
420
  std_dev = data.get("std_dev", 0.0)
@@ -1077,16 +1050,37 @@ class SmartBudgetRecommender:
1077
  else:
1078
  variability_level = "VERY LOW VARIABILITY - very predictable spending"
1079
 
1080
- summary = (
1081
- f"Category: {category}\n"
1082
- f"Monthly spending values: [{history}]\n"
1083
- f"Average monthly spend: {avg_expense:,.2f}\n"
1084
- f"Standard deviation: {data['std_dev']:,.2f}\n"
1085
- f"Coefficient of variation: {cv:.1f}% ({variability_level})\n"
1086
- f"Number of months analyzed: {data['months_analyzed']}\n"
1087
- f"Total spending: {data.get('total', avg_expense * data['months_analyzed']):,.2f}\n"
1088
- f"Trend Analysis: {trend_analysis}\n"
1089
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1090
 
1091
  prompt = (
1092
  "You are an expert global personal finance coach with deep knowledge of:\n"
 
377
  # Generate recommendation
378
  print(f"🔍 get_recommendation_for_category: Generating recommendation for category_name={category_name}, avg_expense={avg_expense}")
379
 
380
+ # If we only have budget_amount (no historical data), use it directly
381
+ # DO NOT create fake/simulated data - be honest with OpenAI that this is a new budget
382
  if using_budget_amount_only:
383
+ # Use the budget_amount as a single data point
384
+ # Don't create fake trends - OpenAI should recommend based on:
385
+ # 1. The budget amount provided
386
+ # 2. Category-specific knowledge
387
+ # 3. General inflation and best practices
388
+ monthly_values = [avg_expense] # Single data point - no fake history
389
+ std_dev = avg_expense * 0.05 # Assume 5% typical variation for new budgets
390
+ months_analyzed = 1 # Only one month of data (the provided budget_amount)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  else:
392
  monthly_values = data.get("monthly_values", [avg_expense])
393
  std_dev = data.get("std_dev", 0.0)
 
1050
  else:
1051
  variability_level = "VERY LOW VARIABILITY - very predictable spending"
1052
 
1053
+ # Check if this is a new budget (no historical data)
1054
+ is_new_budget = len(monthly_values) == 1 and data.get('months_analyzed', 0) == 1
1055
+
1056
+ if is_new_budget:
1057
+ # This is a new budget - no historical data
1058
+ summary = (
1059
+ f"Category: {category}\n"
1060
+ f"⚠️ IMPORTANT: This is a NEW BUDGET with NO historical spending data.\n"
1061
+ f"The user has provided a budget amount of {avg_expense:,.2f} for this category.\n"
1062
+ f"This is the ONLY data point available - there is NO spending history to analyze.\n\n"
1063
+ f"Your recommendation should be based on:\n"
1064
+ f" 1. The provided budget amount: {avg_expense:,.2f}\n"
1065
+ f" 2. Category-specific knowledge (e.g., Food & Drinks inflation, Transport volatility)\n"
1066
+ f" 3. General best practices (add 10-15% buffer for new budgets to account for variability)\n"
1067
+ f" 4. Economic factors (inflation typically 2-5% annually, category-specific inflation)\n\n"
1068
+ f"DO NOT reference fake trends or historical patterns - this is a new budget!\n"
1069
+ f"Recommend a budget that accounts for typical variability and inflation for this category.\n"
1070
+ f"For new budgets, typically recommend 10-15% increase from the provided amount to create a safety buffer.\n"
1071
+ )
1072
+ else:
1073
+ # This is based on real historical data
1074
+ summary = (
1075
+ f"Category: {category}\n"
1076
+ f"Monthly spending values: [{history}]\n"
1077
+ f"Average monthly spend: {avg_expense:,.2f}\n"
1078
+ f"Standard deviation: {data['std_dev']:,.2f}\n"
1079
+ f"Coefficient of variation: {cv:.1f}% ({variability_level})\n"
1080
+ f"Number of months analyzed: {data['months_analyzed']}\n"
1081
+ f"Total spending: {data.get('total', avg_expense * data['months_analyzed']):,.2f}\n"
1082
+ f"Trend Analysis: {trend_analysis}\n"
1083
+ )
1084
 
1085
  prompt = (
1086
  "You are an expert global personal finance coach with deep knowledge of:\n"