Spaces:
Running on Zero
fix(hf-space): actionable error for HF inference model_not_supported
Browse filesUser-reported live (Gemma 2 9B via HF API):
BadRequestError: ...'model 'google/gemma-2-9b-it' is not supported
by any provider you have enabled.'... 'code': 'model_not_supported'
Verbose error reporting from prior commit surfaces this cleanly, but
the BadRequestError stringification is dense JSON dict syntax that
hides the actually-fixable bit. Caught the specific case and re-raise
with two clear options:
(a) enable a provider that serves the requested model at
https://huggingface.co/settings/inference-providers
(b) set HF_MODEL_ID env var to a different model — recommend
microsoft/Phi-4-mini-instruct, broadly supported via
featherless-ai
Default HF_MODEL_ID left as google/gemma-2-9b-it for now — it's the
better-known model and many users will have hf-inference / together-ai
enabled by default, where it works. The new error message guides the
minority case where it doesn't.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@@ -303,14 +303,34 @@ def _call_huggingface(system_block: str, user_prompt: str) -> str:
|
|
| 303 |
"Until then, pick a different model from the dropdown."
|
| 304 |
)
|
| 305 |
client = InferenceClient(model=HF_MODEL_ID, token=token, timeout=120)
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
return resp.choices[0].message.content
|
| 315 |
|
| 316 |
|
|
|
|
| 303 |
"Until then, pick a different model from the dropdown."
|
| 304 |
)
|
| 305 |
client = InferenceClient(model=HF_MODEL_ID, token=token, timeout=120)
|
| 306 |
+
try:
|
| 307 |
+
resp = client.chat_completion(
|
| 308 |
+
messages=[
|
| 309 |
+
{"role": "system", "content": system_block},
|
| 310 |
+
{"role": "user", "content": user_prompt},
|
| 311 |
+
],
|
| 312 |
+
max_tokens=2500,
|
| 313 |
+
temperature=0.2,
|
| 314 |
+
)
|
| 315 |
+
except Exception as e:
|
| 316 |
+
msg = str(e)
|
| 317 |
+
# HF Inference Providers routes each model through a partner
|
| 318 |
+
# (featherless-ai, together-ai, hf-inference, etc.). If none of
|
| 319 |
+
# the enabled providers serves the requested model, the API
|
| 320 |
+
# returns a BadRequestError with code=model_not_supported. The
|
| 321 |
+
# raw error is opaque to users, so re-raise with the actual fix
|
| 322 |
+
# instead of the unhelpful default message.
|
| 323 |
+
if "model_not_supported" in msg or "not supported by any provider" in msg:
|
| 324 |
+
raise RuntimeError(
|
| 325 |
+
f"The model '{HF_MODEL_ID}' isn't available through any of "
|
| 326 |
+
f"the HuggingFace Inference Providers enabled on your account. "
|
| 327 |
+
f"Two fixes: (a) enable a provider that supports this model at "
|
| 328 |
+
f"https://huggingface.co/settings/inference-providers, OR "
|
| 329 |
+
f"(b) set HF_MODEL_ID as a Space variable to a model on your "
|
| 330 |
+
f"enabled providers — microsoft/Phi-4-mini-instruct works "
|
| 331 |
+
f"broadly via featherless-ai."
|
| 332 |
+
)
|
| 333 |
+
raise
|
| 334 |
return resp.choices[0].message.content
|
| 335 |
|
| 336 |
|