Khanna, Videh Rakesh Rakesh commited on
Commit
53e9cd2
·
1 Parent(s): 5a5c4f8

fix: add fallback to free models when Claude credits exhausted in /api/ask

Browse files
Files changed (1) hide show
  1. server.py +10 -0
server.py CHANGED
@@ -114,6 +114,16 @@ async def ask_jarvis(req: Request):
114
  except Exception as e:
115
  return {"error": str(e)}
116
 
 
 
 
 
 
 
 
 
 
 
117
  # Apply STM
118
  cleaned = apply_stm(full_response, aggressive=True)
119
 
 
114
  except Exception as e:
115
  return {"error": str(e)}
116
 
117
+ # Fallback: if primary backend returned an error, retry with free models
118
+ if full_response.startswith("Error:") or full_response.startswith("\nError:"):
119
+ if backend in ("auto", "claude"):
120
+ full_response = ""
121
+ try:
122
+ async for chunk in stream_response(messages, system, "openrouter", params):
123
+ full_response += chunk
124
+ except Exception:
125
+ pass
126
+
127
  # Apply STM
128
  cleaned = apply_stm(full_response, aggressive=True)
129