sharktide commited on
Commit
a90dfbb
·
verified ·
1 Parent(s): fced65c

Update gen.py

Browse files
Files changed (1) hide show
  1. gen.py +10 -5
gen.py CHANGED
@@ -709,11 +709,16 @@ async def generate_text(
709
  if not line:
710
  yield "\n", chosen_model
711
  continue
712
- if '"error"' in line.lower():
713
- print("[STREAM FALLBACK] Error detected inside SSE → switching to Groq fallback")
714
- async for chunk in stream_fallback(client, body):
715
- yield chunk, fallback_model
716
- return
 
 
 
 
 
717
 
718
  yield line + "\n", chosen_model
719
 
 
709
  if not line:
710
  yield "\n", chosen_model
711
  continue
712
+ if line.startswith("event: error"):
713
+ fallback()
714
+
715
+ if line.startswith("data:"):
716
+ try:
717
+ obj = json.loads(line[5:].strip())
718
+ if isinstance(obj, dict) and "error" in obj and isinstance(obj["error"], dict):
719
+ fallback()
720
+ except:
721
+ pass
722
 
723
  yield line + "\n", chosen_model
724