MJ-Prod commited on
Commit
f0d57e4
·
1 Parent(s): e14488e

JWT-update_3

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -35,6 +35,7 @@ SUPABASE_HEADERS = {
35
 
36
  class ChatRequest(BaseModel):
37
  message: str
 
38
 
39
  class ChatResponse(BaseModel):
40
  answer: str
@@ -75,7 +76,8 @@ def chat(
75
  if not user:
76
  raise HTTPException(status_code=401, detail="Invalid or expired token")
77
 
78
- access_token = get_user_access_token(user["sub"])
 
79
  financial_context = get_financial_snapshot(access_token)
80
 
81
  answer = get_answer(
@@ -106,7 +108,7 @@ def chat_stream(
106
 
107
  financial_context = ""
108
  try:
109
- access_token = get_user_access_token(user["sub"])
110
  financial_context = get_financial_snapshot(access_token)
111
  financial_context = financial_context.replace("{", "(").replace("}", ")")
112
  except Exception as e:
@@ -154,7 +156,7 @@ def plaid_exchange_token(
154
  except Exception as e:
155
  print(f"Exchange token error: {e}")
156
  raise HTTPException(status_code=500, detail=str(e))
157
-
158
 
159
  @app.delete("/account")
160
  def delete_account(
 
35
 
36
  class ChatRequest(BaseModel):
37
  message: str
38
+ access_token: str = ""
39
 
40
  class ChatResponse(BaseModel):
41
  answer: str
 
76
  if not user:
77
  raise HTTPException(status_code=401, detail="Invalid or expired token")
78
 
79
+ # Use token from request if provided, fallback to sandbox
80
+ access_token = request.access_token if request.access_token else SANDBOX_ACCESS_TOKEN
81
  financial_context = get_financial_snapshot(access_token)
82
 
83
  answer = get_answer(
 
108
 
109
  financial_context = ""
110
  try:
111
+ access_token = request.access_token if request.access_token else SANDBOX_ACCESS_TOKEN
112
  financial_context = get_financial_snapshot(access_token)
113
  financial_context = financial_context.replace("{", "(").replace("}", ")")
114
  except Exception as e:
 
156
  except Exception as e:
157
  print(f"Exchange token error: {e}")
158
  raise HTTPException(status_code=500, detail=str(e))
159
+
160
 
161
  @app.delete("/account")
162
  def delete_account(