Commit
·
2210c72
1
Parent(s):
f26b6aa
Add explicit instructions and system message to ensure OpenAI provides unique reasons for each recommendation
Browse files- app/smart_recommendation.py +39 -8
app/smart_recommendation.py
CHANGED
|
@@ -1181,13 +1181,40 @@ class SmartBudgetRecommender:
|
|
| 1181 |
"Even then, add at least 5% buffer for inflation!\n\n"
|
| 1182 |
"Respond strictly as JSON with the following keys:\n"
|
| 1183 |
'{ "recommended_budget": number, "action": "increase|decrease|keep", "reason": "string" }.\n\n'
|
| 1184 |
-
"The 'reason' field is CRITICAL - it must:\n"
|
| 1185 |
-
"-
|
| 1186 |
-
"
|
| 1187 |
-
"
|
| 1188 |
-
"-
|
| 1189 |
-
"- Use your
|
| 1190 |
-
"-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1191 |
"Round recommended_budget to nearest 100. Use appropriate currency context in your reasoning.\n"
|
| 1192 |
"Example reason: 'Your spending on Food & Drinks shows an upward trend (1800 → 2000 over 3 months), "
|
| 1193 |
"likely due to food inflation (typically 3-5% annually globally). I recommend increasing your budget by 15% "
|
|
@@ -1204,9 +1231,13 @@ class SmartBudgetRecommender:
|
|
| 1204 |
json={
|
| 1205 |
"model": "gpt-4o-mini",
|
| 1206 |
"messages": [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1207 |
{"role": "user", "content": prompt}
|
| 1208 |
],
|
| 1209 |
-
"temperature":
|
| 1210 |
"response_format": {"type": "json_object"},
|
| 1211 |
},
|
| 1212 |
timeout=30,
|
|
|
|
| 1181 |
"Even then, add at least 5% buffer for inflation!\n\n"
|
| 1182 |
"Respond strictly as JSON with the following keys:\n"
|
| 1183 |
'{ "recommended_budget": number, "action": "increase|decrease|keep", "reason": "string" }.\n\n'
|
| 1184 |
+
"The 'reason' field is CRITICAL - it must be UNIQUE and SPECIFIC:\n"
|
| 1185 |
+
"🚨 MANDATORY: Each reason MUST be completely UNIQUE - never reuse the same reason!\n\n"
|
| 1186 |
+
"UNIQUENESS REQUIREMENTS:\n"
|
| 1187 |
+
"1. VARY YOUR LANGUAGE:\n"
|
| 1188 |
+
" - Don't start every reason with 'Your spending shows...'\n"
|
| 1189 |
+
" - Use different opening phrases: 'Analyzing your data...', 'Based on the pattern...', 'I've reviewed...', etc.\n"
|
| 1190 |
+
" - Vary sentence structure and word choice\n\n"
|
| 1191 |
+
"2. FOCUS ON DIFFERENT ASPECTS:\n"
|
| 1192 |
+
" - For some recommendations, emphasize the TREND (increasing/decreasing)\n"
|
| 1193 |
+
" - For others, emphasize VARIABILITY (high/low volatility)\n"
|
| 1194 |
+
" - For others, emphasize INFLATION or category-specific factors\n"
|
| 1195 |
+
" - Mix and match - don't always focus on the same thing\n\n"
|
| 1196 |
+
"3. REFERENCE SPECIFIC DATA:\n"
|
| 1197 |
+
" - MUST include actual numbers from the data (e.g., 'from 9,400,000 to 10,400,000')\n"
|
| 1198 |
+
" - MUST mention specific percentages (e.g., '10.6% increase', '5.7% coefficient of variation')\n"
|
| 1199 |
+
" - MUST reference the category name and specific characteristics\n\n"
|
| 1200 |
+
"4. USE DIFFERENT EXPLANATIONS:\n"
|
| 1201 |
+
" - Sometimes explain inflation impact\n"
|
| 1202 |
+
" - Sometimes explain variability needs\n"
|
| 1203 |
+
" - Sometimes explain trend implications\n"
|
| 1204 |
+
" - Sometimes combine multiple factors\n\n"
|
| 1205 |
+
"5. VARY YOUR TONE AND STYLE:\n"
|
| 1206 |
+
" - Some reasons can be more analytical\n"
|
| 1207 |
+
" - Some can be more advisory\n"
|
| 1208 |
+
" - Some can emphasize different benefits\n\n"
|
| 1209 |
+
"⚠️ CRITICAL: If you find yourself writing a similar reason, STOP and rewrite it with:\n"
|
| 1210 |
+
" - Different opening phrase\n"
|
| 1211 |
+
" - Different focus (trend vs variability vs inflation)\n"
|
| 1212 |
+
" - Different examples or explanations\n"
|
| 1213 |
+
" - Different sentence structure\n\n"
|
| 1214 |
+
"Example of UNIQUE reasons (notice how different they are):\n"
|
| 1215 |
+
"- 'Analyzing your Food & Drinks spending, I observe a 10.6% upward trajectory from 9.4M to 10.4M. With food inflation typically at 3-5% annually and your low 5.7% variability, I suggest increasing to 11.2M to accommodate price trends.'\n"
|
| 1216 |
+
"- 'Your Transport category displays significant volatility (18% coefficient of variation), indicating unpredictable fuel costs. To ensure financial stability, I recommend a 25% buffer increase to 12.5M.'\n"
|
| 1217 |
+
"- 'Based on Entertainment spending patterns, the data shows stability with occasional spikes. Accounting for weekend and holiday variations, a modest 8% increase to 5.4M would provide adequate coverage.'\n\n"
|
| 1218 |
"Round recommended_budget to nearest 100. Use appropriate currency context in your reasoning.\n"
|
| 1219 |
"Example reason: 'Your spending on Food & Drinks shows an upward trend (1800 → 2000 over 3 months), "
|
| 1220 |
"likely due to food inflation (typically 3-5% annually globally). I recommend increasing your budget by 15% "
|
|
|
|
| 1231 |
json={
|
| 1232 |
"model": "gpt-4o-mini",
|
| 1233 |
"messages": [
|
| 1234 |
+
{
|
| 1235 |
+
"role": "system",
|
| 1236 |
+
"content": "You are an expert personal finance coach. CRITICAL: Each recommendation reason MUST be completely unique. Never reuse the same language, phrases, or structure. Vary your explanations, focus on different aspects (trends vs variability vs inflation), and use different sentence structures for each recommendation."
|
| 1237 |
+
},
|
| 1238 |
{"role": "user", "content": prompt}
|
| 1239 |
],
|
| 1240 |
+
"temperature": 1.2, # High temperature for maximum variation and creativity
|
| 1241 |
"response_format": {"type": "json_object"},
|
| 1242 |
},
|
| 1243 |
timeout=30,
|