Revert "fix tests (#12286)"

This reverts commit 99ce3a24cc.
This commit is contained in:
Ishaan Jaff 2025-07-03 12:04:23 -07:00
parent 9cc144e3cb
commit 12f157513b
3 changed files with 41 additions and 35 deletions

View File

@ -109,19 +109,22 @@ class HuggingFaceChatConfig(OpenAIGPTConfig):
# Default construction with provider
else:
# 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 slash
complete_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 = model
if "/" in remaining:
provider = first_part
model_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(

View File

@ -2,21 +2,19 @@
Test HuggingFace LLM
"""
from base_llm_unit_tests import BaseLLMChatTest
import json
import os
import sys
from unittest.mock import AsyncMock, MagicMock, patch
from base_llm_unit_tests import BaseLLMChatTest
from unittest.mock import patch, MagicMock, AsyncMock
sys.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, ModelResponse
MOCK_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 HuggingFaceChatConfig

View File

@ -3975,7 +3975,7 @@ def test_text_completion_stream():
try:
for _ in range(2): # check if closed client used
response = text_completion(
model="huggingface/deepseek-ai/DeepSeek-R1",
model="huggingface/sarvamai/sarvam-m",
prompt="good morning",
stream=True,
max_tokens=10,