Composer fallbacks: three distinct verified providers, per-provider timeouts, attempt logging

#7
by multimodalart HF Staff - opened
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -502,11 +502,17 @@ def _llm_json(system, user):
502
  from openai import OpenAI
503
 
504
  # Bounded timeout: a hung provider must fail over, not freeze the UI at the composing step.
505
- client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], timeout=60, max_retries=0)
506
  last_error = None
507
- for model in ("deepseek-ai/DeepSeek-V4-Flash-0731:baseten", "deepseek-ai/DeepSeek-V4-Flash-0731", "deepseek-ai/DeepSeek-V4-Flash-0731:fastest"):
 
 
 
 
 
 
508
  try:
509
- completion = client.chat.completions.create(
510
  model=model,
511
  messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],
512
  )
@@ -517,9 +523,10 @@ def _llm_json(system, user):
517
  raise ValueError(f"no JSON object in composer reply (finish_reason={completion.choices[0].finish_reason})")
518
  return _json.loads(text[start : end + 1])
519
  except Exception as e:
 
520
  last_error = e
521
  raise gr.Error(
522
- "The MiniMax-M3 composer is overloaded right now — try again in a moment, "
523
  "or write the lyrics and structured prompt directly in the Studio tab."
524
  ) from last_error
525
 
 
502
  from openai import OpenAI
503
 
504
  # Bounded timeout: a hung provider must fail over, not freeze the UI at the composing step.
505
+ client = OpenAI(base_url="https://router.huggingface.co/v1", api_key=os.environ["HF_TOKEN"], max_retries=0)
506
  last_error = None
507
+ # Three DISTINCT providers, all verified enabled for this account (bare/":fastest" can route to
508
+ # together, which 403s here and killed the fallbacks). Timeouts sized to measured composer latency.
509
+ for model, timeout in (
510
+ ("deepseek-ai/DeepSeek-V4-Flash-0731:baseten", 45),
511
+ ("deepseek-ai/DeepSeek-V4-Flash-0731:deepinfra", 75),
512
+ ("deepseek-ai/DeepSeek-V4-Flash-0731:novita", 100),
513
+ ):
514
  try:
515
+ completion = client.with_options(timeout=timeout).chat.completions.create(
516
  model=model,
517
  messages=[{"role": "system", "content": system}, {"role": "user", "content": user}],
518
  )
 
523
  raise ValueError(f"no JSON object in composer reply (finish_reason={completion.choices[0].finish_reason})")
524
  return _json.loads(text[start : end + 1])
525
  except Exception as e:
526
+ print(f"composer attempt failed ({model}): {type(e).__name__}: {e}", flush=True)
527
  last_error = e
528
  raise gr.Error(
529
+ "The composer model is overloaded right now — try again in a moment, "
530
  "or write the lyrics and structured prompt directly in the Studio tab."
531
  ) from last_error
532