Upload hf_inference.py
Browse files- core/hf_inference.py +13 -3
core/hf_inference.py
CHANGED
|
@@ -333,9 +333,19 @@ class HFInferenceClient:
|
|
| 333 |
if not self.token:
|
| 334 |
raise ValueError("HF_TOKEN is required for inference")
|
| 335 |
|
| 336 |
-
#
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
def get_model_for_agent(self, agent_name: str) -> str:
|
| 341 |
"""Get the appropriate model for an agent."""
|
|
|
|
| 333 |
if not self.token:
|
| 334 |
raise ValueError("HF_TOKEN is required for inference")
|
| 335 |
|
| 336 |
+
# New HuggingFace router URL (api-inference is deprecated)
|
| 337 |
+
# The huggingface_hub library should handle this automatically with newer versions,
|
| 338 |
+
# but we set it explicitly for compatibility
|
| 339 |
+
router_url = "https://router.huggingface.co"
|
| 340 |
+
|
| 341 |
+
# Create clients with explicit base_url for new router
|
| 342 |
+
try:
|
| 343 |
+
self.sync_client = InferenceClient(token=self.token, base_url=router_url)
|
| 344 |
+
self.async_client = AsyncInferenceClient(token=self.token, base_url=router_url)
|
| 345 |
+
except TypeError:
|
| 346 |
+
# Fallback for older huggingface_hub versions that don't support base_url
|
| 347 |
+
self.sync_client = InferenceClient(token=self.token)
|
| 348 |
+
self.async_client = AsyncInferenceClient(token=self.token)
|
| 349 |
|
| 350 |
def get_model_for_agent(self, agent_name: str) -> str:
|
| 351 |
"""Get the appropriate model for an agent."""
|