mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-06 10:21:32 +00:00
@@ -109,22 +109,19 @@ 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
|
||||
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}"
|
||||
|
||||
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
|
||||
@@ -145,25 +142,24 @@ 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
|
||||
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"]
|
||||
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(
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
Test HuggingFace LLM
|
||||
"""
|
||||
|
||||
from base_llm_unit_tests import BaseLLMChatTest
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from base_llm_unit_tests import BaseLLMChatTest
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../..")
|
||||
) # Adds the parent directory to the system path
|
||||
|
||||
import litellm
|
||||
import pytest
|
||||
from litellm.types.utils import ModelResponseStream, ModelResponse
|
||||
|
||||
import litellm
|
||||
from litellm.types.utils import ModelResponse, ModelResponseStream
|
||||
|
||||
MOCK_COMPLETION_RESPONSE = {
|
||||
"id": "9115d3daeab10608",
|
||||
@@ -361,31 +363,27 @@ class TestHuggingFace(BaseLLMChatTest):
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model, provider, expected_url",
|
||||
"model, expected_url",
|
||||
[
|
||||
(
|
||||
"meta-llama/Llama-3-8B-Instruct",
|
||||
None,
|
||||
"https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3-8B-Instruct/v1/chat/completions",
|
||||
"https://router.huggingface.co/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, provider, expected_url):
|
||||
def test_get_complete_url(self, model, expected_url):
|
||||
"""Test that the complete URL is constructed correctly for different providers"""
|
||||
from litellm.llms.huggingface.chat.transformation import HuggingFaceChatConfig
|
||||
|
||||
|
||||
@@ -3975,7 +3975,7 @@ def test_text_completion_stream():
|
||||
try:
|
||||
for _ in range(2): # check if closed client used
|
||||
response = text_completion(
|
||||
model="huggingface/sarvamai/sarvam-m",
|
||||
model="huggingface/deepseek-ai/DeepSeek-R1",
|
||||
prompt="good morning",
|
||||
stream=True,
|
||||
max_tokens=10,
|
||||
|
||||
Reference in New Issue
Block a user