The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Revert "fix tests (#12286)"
Ishaan Jaff12f157513b05
diff --git a/litellm/llms/huggingface/chat/transformation.py b/litellm/llms/huggingface/chat/transformation.pyindex 557aa48550b..03ae2a52ac3 100644--- a/litellm/llms/huggingface/chat/transformation.py+++ b/litellm/llms/huggingface/chat/transformation.py@@ -109,19 +109,22 @@ class HuggingFaceChatConfig(OpenAIGPTConfig):# Default construction with providerelse:# Parse provider and model- complete_url = "https://router.huggingface.co/v1/chat/completions"first_part, remaining = model.split("/", 1)if "/" in remaining:provider = first_part- if provider == "hf-inference":- route = f"{provider}/models/{model}/v1/chat/completions"- elif provider == "novita":- route = f"{provider}/v3/openai/chat/completions"- elif provider == "fireworks-ai":- route = f"{provider}/inference/v1/chat/completions"- else:- route = f"{provider}/v1/chat/completions"- complete_url = f"{BASE_URL}/{route}"+ else:+ provider = "hf-inference"++ if provider == "hf-inference":+ route = f"{provider}/models/{model}/v1/chat/completions"+ elif provider == "novita":+ route = f"{provider}/v3/openai/chat/completions"+ elif provider == "fireworks-ai":+ route = f"{provider}/inference/v1/chat/completions"+ else:+ route = f"{provider}/v1/chat/completions"+ complete_url = f"{BASE_URL}/{route}"+# Ensure URL doesn't end with a slashcomplete_url = complete_url.rstrip("/")return complete_url@@ -142,24 +145,25 @@ class HuggingFaceChatConfig(OpenAIGPTConfig):logger.warning("`max_retries` is not supported. It will be ignored.")optional_params.pop("max_retries", None)first_part, remaining = model.split("/", 1)- mapped_model = modelif "/" in remaining:provider = first_partmodel_id = remaining- provider_mapping = _fetch_inference_provider_mapping(model_id)- if provider not in provider_mapping:- raise HuggingFaceError(- message=f"Model {model_id} is not supported for provider {provider}",- status_code=404,- headers={},- )- provider_mapping = provider_mapping[provider]- if provider_mapping["status"] == "staging":- logger.warning(- f"Model {model_id} is in staging mode for provider {provider}. Meant for test purposes only."- )- mapped_model = provider_mapping["providerId"]-+ else:+ provider = "hf-inference"+ model_id = model+ provider_mapping = _fetch_inference_provider_mapping(model_id)+ if provider not in provider_mapping:+ raise HuggingFaceError(+ message=f"Model {model_id} is not supported for provider {provider}",+ status_code=404,+ headers={},+ )+ provider_mapping = provider_mapping[provider]+ if provider_mapping["status"] == "staging":+ logger.warning(+ f"Model {model_id} is in staging mode for provider {provider}. Meant for test purposes only."+ )+ mapped_model = provider_mapping["providerId"]messages = self._transform_messages(messages=messages, model=mapped_model)return dict(ChatCompletionRequest(diff --git a/tests/llm_translation/test_huggingface_chat_completion.py b/tests/llm_translation/test_huggingface_chat_completion.pyindex cdf3f9ef76f..ae8ed3a4303 100644--- a/tests/llm_translation/test_huggingface_chat_completion.py+++ b/tests/llm_translation/test_huggingface_chat_completion.py@@ -2,21 +2,19 @@Test HuggingFace LLM"""+from base_llm_unit_tests import BaseLLMChatTestimport jsonimport osimport sys-from unittest.mock import AsyncMock, MagicMock, patch--from base_llm_unit_tests import BaseLLMChatTest+from unittest.mock import patch, MagicMock, AsyncMocksys.path.insert(0, os.path.abspath("../..")) # Adds the parent directory to the system path-import pytest-import litellm-from litellm.types.utils import ModelResponse, ModelResponseStream+import pytest+from litellm.types.utils import ModelResponseStream, ModelResponseMOCK_COMPLETION_RESPONSE = {"id": "9115d3daeab10608",@@ -363,27 +361,31 @@ class TestHuggingFace(BaseLLMChatTest):)@pytest.mark.parametrize(- "model, expected_url",+ "model, provider, expected_url",[("meta-llama/Llama-3-8B-Instruct",- "https://router.huggingface.co/v1/chat/completions",+ None,+ "https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3-8B-Instruct/v1/chat/completions",),("together/meta-llama/Llama-3-8B-Instruct",+ None,"https://router.huggingface.co/together/v1/chat/completions",),("novita/meta-llama/Llama-3-8B-Instruct",+ None,"https://router.huggingface.co/novita/v3/openai/chat/completions",),("http://custom-endpoint.com/v1/chat/completions",+ None,"http://custom-endpoint.com/v1/chat/completions",),],)- def test_get_complete_url(self, model, expected_url):+ def test_get_complete_url(self, model, provider, expected_url):"""Test that the complete URL is constructed correctly for different providers"""from litellm.llms.huggingface.chat.transformation import HuggingFaceChatConfigdiff --git a/tests/local_testing/test_text_completion.py b/tests/local_testing/test_text_completion.pyindex a0cf2c7ec0b..daca0b0eb76 100644--- a/tests/local_testing/test_text_completion.py+++ b/tests/local_testing/test_text_completion.py@@ -3975,7 +3975,7 @@ def test_text_completion_stream():try:for _ in range(2): # check if closed client usedresponse = text_completion(- model="huggingface/deepseek-ai/DeepSeek-R1",+ model="huggingface/sarvamai/sarvam-m",prompt="good morning",stream=True,max_tokens=10,