Commit
·
46c4337
1
Parent(s):
6ec895c
Add enhanced logging to track OpenAI API usage vs rule-based recommendations
Browse files
app/smart_recommendation.py
CHANGED
|
@@ -75,16 +75,16 @@ class SmartBudgetRecommender:
|
|
| 75 |
recommended_budget = ai_result.get("recommended_budget")
|
| 76 |
reason = ai_result.get("reason", f"AI recommendation for {category}")
|
| 77 |
action = ai_result.get("action")
|
| 78 |
-
print(f"OpenAI recommendation for {category}: {recommended_budget}")
|
| 79 |
else:
|
| 80 |
# Fallback to rule-based recommendation if OpenAI fails
|
| 81 |
recommended_budget = self._calculate_recommended_budget(avg_expense, data)
|
| 82 |
reason = self._generate_reason(category, avg_expense, recommended_budget)
|
| 83 |
action = None
|
| 84 |
if not ai_result:
|
| 85 |
-
print(f"OpenAI unavailable, using rule-based for {category}: {recommended_budget}")
|
| 86 |
else:
|
| 87 |
-
print(f"OpenAI returned invalid data, using rule-based for {category}: {recommended_budget}")
|
| 88 |
|
| 89 |
recommendations.append(BudgetRecommendation(
|
| 90 |
category=category,
|
|
@@ -528,7 +528,10 @@ class SmartBudgetRecommender:
|
|
| 528 |
def _get_ai_recommendation(self, category: str, data: Dict, avg_expense: float):
|
| 529 |
"""Use OpenAI to refine the budget recommendation."""
|
| 530 |
if not OPENAI_API_KEY:
|
|
|
|
| 531 |
return None
|
|
|
|
|
|
|
| 532 |
|
| 533 |
# Handle empty monthly_values
|
| 534 |
if not data.get("monthly_values") or len(data["monthly_values"]) == 0:
|
|
|
|
| 75 |
recommended_budget = ai_result.get("recommended_budget")
|
| 76 |
reason = ai_result.get("reason", f"AI recommendation for {category}")
|
| 77 |
action = ai_result.get("action")
|
| 78 |
+
print(f"✅ OpenAI recommendation for {category}: {recommended_budget} (action: {action})")
|
| 79 |
else:
|
| 80 |
# Fallback to rule-based recommendation if OpenAI fails
|
| 81 |
recommended_budget = self._calculate_recommended_budget(avg_expense, data)
|
| 82 |
reason = self._generate_reason(category, avg_expense, recommended_budget)
|
| 83 |
action = None
|
| 84 |
if not ai_result:
|
| 85 |
+
print(f"❌ OpenAI unavailable (no API key or error), using rule-based for {category}: {recommended_budget}")
|
| 86 |
else:
|
| 87 |
+
print(f"⚠️ OpenAI returned invalid data, using rule-based for {category}: {recommended_budget}")
|
| 88 |
|
| 89 |
recommendations.append(BudgetRecommendation(
|
| 90 |
category=category,
|
|
|
|
| 528 |
def _get_ai_recommendation(self, category: str, data: Dict, avg_expense: float):
|
| 529 |
"""Use OpenAI to refine the budget recommendation."""
|
| 530 |
if not OPENAI_API_KEY:
|
| 531 |
+
print(f"⚠️ OpenAI API key not found in environment variables for category: {category}")
|
| 532 |
return None
|
| 533 |
+
|
| 534 |
+
print(f"🔄 Calling OpenAI API for category: {category}...")
|
| 535 |
|
| 536 |
# Handle empty monthly_values
|
| 537 |
if not data.get("monthly_values") or len(data["monthly_values"]) == 0:
|