MJ-Prod commited on
Commit
28df5d8
·
1 Parent(s): b2a10e5

updated output

Browse files
Files changed (2) hide show
  1. fiscal.py +9 -4
  2. plaid_client.py +1 -5
fiscal.py CHANGED
@@ -76,7 +76,7 @@ QA_TEMPLATE = """You are FISCAL, a friendly AI assistant for Canadian banking, p
76
  The user has connected their bank account. Here is their live financial data:
77
  {financial_context}
78
 
79
- Answer using ONLY the context below combined with the financial data above. Do not add facts not in the context. Do not mention any underlying AI model. If the context does not contain enough info, say so briefly and offer to help with a related Canadian finance topic. If the question is a greeting or casual message, respond warmly and briefly introduce yourself as FISCAL, a Canadian personal finance assistant. Otherwise, answer using the context below combined with the financial data above. Do not add facts not in the context. Do not mention any underlying AI model. If the context does not contain enough information, say so briefly and offer to help with a related Canadian finance topic.
80
 
81
  Context:
82
  {context}
@@ -100,10 +100,16 @@ def _get_memory(user_id: str) -> ConversationBufferMemory:
100
 
101
 
102
  def get_answer(message: str, user_id: str, financial_context: str = "") -> str:
103
- # Build prompt with financial context already filled in
 
 
 
 
 
 
104
  filled_template = QA_TEMPLATE.replace(
105
  "{financial_context}",
106
- financial_context or "No bank data available."
107
  )
108
 
109
  prompt = PromptTemplate(
@@ -123,7 +129,6 @@ def get_answer(message: str, user_id: str, financial_context: str = "") -> str:
123
  result = chain.invoke({"question": message})
124
  return result["answer"]
125
 
126
-
127
  def clear_memory(user_id: str) -> None:
128
  if user_id in _memory_store:
129
  _memory_store[user_id].clear()
 
76
  The user has connected their bank account. Here is their live financial data:
77
  {financial_context}
78
 
79
+ Answer using ONLY the context below combined with the financial data above. Do not add facts not in the context. Do not mention any underlying AI model. If the context does not contain enough info, say so briefly and offer to help with a related Canadian finance topic. If the question is a greeting or casual message, respond warmly and briefly introduce yourself as FISCAL, a Canadian personal finance assistant. Otherwise, answer using the context below combined with the financial data above. Do not add facts not in the context. Do not mention any underlying AI model. Do not mention Plaid, access tokens, sandbox, or any technical errors. If the context does not contain enough information, say so briefly and offer to help with a related Canadian finance topic. Do not add facts not in the context. Do not mention any underlying AI model. If the context does not contain enough information, say so briefly and offer to help with a related Canadian finance topic.
80
 
81
  Context:
82
  {context}
 
100
 
101
 
102
  def get_answer(message: str, user_id: str, financial_context: str = "") -> str:
103
+
104
+ # Clean financial context — never expose raw errors to the LLM
105
+ if not financial_context or financial_context == "NO_BANK_DATA" or "Unable to fetch" in financial_context or "Bad Request" in financial_context or "access token" in financial_context.lower():
106
+ context_block = "The user has not connected their bank account yet. If relevant, gently mention they can connect their bank account in the Options menu to get personalized advice based on their real transactions and balances."
107
+ else:
108
+ context_block = f"The user has connected their bank account. Here is their live financial data:\n{financial_context}"
109
+
110
  filled_template = QA_TEMPLATE.replace(
111
  "{financial_context}",
112
+ context_block
113
  )
114
 
115
  prompt = PromptTemplate(
 
129
  result = chain.invoke({"question": message})
130
  return result["answer"]
131
 
 
132
  def clear_memory(user_id: str) -> None:
133
  if user_id in _memory_store:
134
  _memory_store[user_id].clear()
plaid_client.py CHANGED
@@ -109,16 +109,12 @@ def get_transactions(access_token: str, days: int = 30) -> str:
109
  # ---------- Combined snapshot ----------
110
 
111
  def get_financial_snapshot(access_token: str) -> str:
112
- """
113
- Returns full financial context string to inject into the LLM prompt.
114
- Combines balances + transaction summary.
115
- """
116
  try:
117
  balances = get_balances(access_token)
118
  transactions = get_transactions(access_token)
119
  return f"{balances}\n\n{transactions}"
120
  except Exception as e:
121
- return f"Unable to fetch account data: {str(e)}"
122
 
123
 
124
 
 
109
  # ---------- Combined snapshot ----------
110
 
111
  def get_financial_snapshot(access_token: str) -> str:
 
 
 
 
112
  try:
113
  balances = get_balances(access_token)
114
  transactions = get_transactions(access_token)
115
  return f"{balances}\n\n{transactions}"
116
  except Exception as e:
117
+ return "NO_BANK_DATA"
118
 
119
 
120