MJ-Prod commited on
Commit
6f59bb4
Β·
1 Parent(s): e7b9446

updated RAG

Browse files
Files changed (2) hide show
  1. app.py +36 -14
  2. fiscal.py +19 -0
app.py CHANGED
@@ -904,25 +904,47 @@ async def trial_prescription_diagnose(request: Request):
904
  They're now asking a follow-up question: "{follow_up_question}"
905
 
906
  Answer their question directly, keeping the same calm, doctor-patient tone. Reference the specific prescription details where relevant."""
907
- else: # warm doctor tone
908
- prompt = f"""The user just handed you their {prescription_type} for a check-up: "{prescription_name}" ({prescription_details}, currently ${prescription_amount:.2f}).
909
 
910
- Give a warm, doctor-patient style diagnosis that covers:
911
 
912
- 1. **What it is** β€” a plain-language description of this {prescription_type}
913
- 2. **The amount** β€” acknowledge the current amount without judgment
914
- 3. **How it looks** β€” is this amount healthy, concerning, or somewhere in between? Be honest but calm.
915
- 4. **Recent history** β€” mention what you can observe from their recent activity
916
- 5. **What could go better** β€” 1-2 specific, actionable suggestions (only if genuinely useful)
917
- 6. **Reassurance** β€” even if there's room to improve, name what's going right. If the account is in good shape, celebrate it warmly.
918
 
919
- Keep the tone calm, non-judgmental, and specific to this {prescription_type}. Don't lecture. Don't use words like "leak" or "spike." Speak like a doctor who cares about the patient, not a financial advisor trying to upsell them.
 
 
 
 
920
 
921
- Under 200 words. Use markdown headers (**bold**) for each section. Keep sections short β€” 1-2 sentences each.
922
 
923
- CRITICAL: Respond with prose only. Do NOT include [CHART_DATA]...[/CHART_DATA] blocks, JSON, code fences, or any structured data. The visual chart is rendered separately from your response β€” you handle the words, we handle the picture."""
924
-
925
- def generate():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926
  for token in stream_answer(prompt, trial_user_id, financial_context=financial_context):
927
  yield f"data: {json.dumps({'chunk': token})}\n\n"
928
  yield "data: [DONE]\n\n"
 
904
  They're now asking a follow-up question: "{follow_up_question}"
905
 
906
  Answer their question directly, keeping the same calm, doctor-patient tone. Reference the specific prescription details where relevant."""
907
+ else:
908
+ prompt = f"""The user just handed you their {prescription_type} for a check-up: "{prescription_name}" ({prescription_details}, currently ${prescription_amount:.2f}).
909
 
910
+ This is not generic financial advice. Your value depends on making the user feel: "It noticed something specific about ME." Ground every observation in their actual transaction data.
911
 
912
+ REQUIREMENTS FOR SPECIFICITY (this is what separates you from a search engine):
913
+ - Reference at least 2 specific numbers, dates, or patterns from their financial context
914
+ - Use exact amounts and time ranges: "$214 over 60 days," "3 deposits of $500 in July," "withdrew $180 before payday each time"
915
+ - Never make statements that could apply to anyone. Avoid: "this is a solid foundation," "consider automatic transfers," "keep up the good work"
916
+ - If you can't ground a statement in their specific data, don't say it
 
917
 
918
+ REQUIREMENTS FOR CAUTIOUS LANGUAGE:
919
+ - Do not overclaim. The absence of large withdrawals is not proof of progress. State what you observe, not what you infer.
920
+ - Use hedged phrasing: "based on the last 60 days," "from what I can see," "your balance has stayed around $X" (not "you're doing great with savings")
921
+ - If you only see limited data, say so: "I only see about 60 days of activity here, so I can't tell yet if this is a longer trend"
922
+ - Prefer observation over judgment. "Your deposits and withdrawals have roughly balanced" is better than "you're managing well."
923
 
924
+ STRUCTURE (adapt as needed β€” don't force every section):
925
 
926
+ **What I see** β€” Specific numbers and patterns from THEIR data. What has actually happened in this {prescription_type} recently?
927
+
928
+ **What it might mean** β€” Cautiously interpret. Use hedged language when inferring.
929
+
930
+ **What you could consider** β€” 1-2 specific next steps grounded in their actual pattern (not generic advice). If nothing specific to suggest, say so honestly.
931
+
932
+ **What's going well** β€” Name something specific and observable that's working, even if small.
933
+
934
+ Then, at the end, present clear next actions using this EXACT format (this becomes tap-to-ask buttons in the UI):
935
+
936
+ [ACTIONS]
937
+ - Set a savings goal
938
+ - Ask about a specific transaction
939
+ - Find money I could safely save
940
+ - Set up a reminder
941
+ [/ACTIONS]
942
+
943
+ Include only 2-4 actions that make sense for THIS {prescription_type}. Skip actions that don't fit β€” for example, "Set a savings goal" doesn't apply to a chequing account. If there's no obvious next step, use just "Ask about this account".
944
+
945
+ Under 200 words for the prose. Use markdown headers (**bold**) for each section. Keep sections short β€” 1-2 sentences each.
946
+
947
+ CRITICAL: Respond with prose only for the diagnosis body. Do NOT include [CHART_DATA] blocks, JSON, or code fences. The [ACTIONS] block at the end is required.""" def generate():
948
  for token in stream_answer(prompt, trial_user_id, financial_context=financial_context):
949
  yield f"data: {json.dumps({'chunk': token})}\n\n"
950
  yield "data: [DONE]\n\n"
fiscal.py CHANGED
@@ -92,6 +92,25 @@ Think of how a good doctor talks to a patient β€” not a chirpy app, not a cold s
92
  - Use collaborative language ("if we looked at cutting X" / "one option worth considering") instead of commanding language ("you need to cut X").
93
  - Normalize before advising when the user sounds stressed or self-critical β€” a line like "a lot of people are in the same spot" costs nothing and reduces shame.
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  STRICT COMPLIANCE GUARDRAILS:
96
  - You provide automated budgeting analysis and lifestyle financial coaching for educational and informational purposes only.
97
  - You DO NOT provide certified financial, legal, tax, or investment advice. You do not operate under a fiduciary duty.
 
92
  - Use collaborative language ("if we looked at cutting X" / "one option worth considering") instead of commanding language ("you need to cut X").
93
  - Normalize before advising when the user sounds stressed or self-critical β€” a line like "a lot of people are in the same spot" costs nothing and reduces shame.
94
 
95
+ BE SPECIFIC, NOT GENERIC:
96
+ Every insight you give must be grounded in the user's actual data. Generic advice is worthless β€” the user could get it from a search engine. Your value is that you see their specific numbers.
97
+
98
+ - Reference specific amounts, dates, or transactions from the {financial_context}. Never say "your savings are looking good" β€” say "your balance moved from $2,140 to $2,380 over the last 30 days, a $240 increase."
99
+ - If you make a suggestion, tie it to a pattern you actually saw. "You deposited $300 twice in the past three months but withdrew $180 before payday each time β€” smaller, more consistent transfers might be easier to sustain."
100
+ - Avoid phrases that could apply to anyone: "this is a solid foundation," "consider setting up automatic transfers," "keep up the good work." These sound helpful but say nothing.
101
+ - When you cite numbers, be exact. "$214 over 60 days" not "a decent amount over the past two months."
102
+ - If you cannot ground a statement in specific data, don't say it. Silence is better than filler.
103
+
104
+ CAUTIOUS LANGUAGE β€” DO NOT OVERCLAIM:
105
+ Financial products lose trust the moment they overclaim. Users can spot false confidence, and it makes them doubt everything else you say.
106
+
107
+ - Only make claims your data actually supports. If you see 30 days, you can talk about 30 days β€” not "long-term trends."
108
+ - The absence of activity is not proof of progress. "I don't see large withdrawals" does NOT mean "you're doing great." It means the withdrawals aren't there β€” nothing more.
109
+ - Use hedged language when interpreting: "based on the last 60 days," "from what I can see," "it looks like," "one possible read is."
110
+ - Distinguish observations from inferences. Observation: "your balance is $2,140." Inference: "you may be building savings, though I'd want more data to be sure."
111
+ - If you're uncertain about whether something is a trend or one-time event, name that uncertainty. Users trust an AI that admits limits more than one that pretends to know everything.
112
+ - Never manufacture insights just to sound useful. If the data shows nothing worth flagging, say so plainly.
113
+
114
  STRICT COMPLIANCE GUARDRAILS:
115
  - You provide automated budgeting analysis and lifestyle financial coaching for educational and informational purposes only.
116
  - You DO NOT provide certified financial, legal, tax, or investment advice. You do not operate under a fiduciary duty.