Skip to content

Commit 893d1ff

Browse files
committed
old versions
1 parent b9f22cc commit 893d1ff

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tests/integrations/huggingface_hub/test_huggingface_hub.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@
55
from huggingface_hub import InferenceClient
66

77
import sentry_sdk
8+
from sentry_sdk.utils import package_version
89

910
from typing import TYPE_CHECKING
1011

1112
if TYPE_CHECKING:
1213
from typing import Any
1314

1415

16+
HF_VERSION = package_version("huggingface-hub")
17+
18+
if HF_VERSION and HF_VERSION < (0, 30, 0):
19+
MODEL_ENDPOINT = "https://api-inference.huggingface.co/models/{model_name}"
20+
INFERENCE_ENDPOINT = "https://api-inference.huggingface.co/models/{model_name}"
21+
else:
22+
MODEL_ENDPOINT = "https://huggingface.co/api/models/{model_name}"
23+
INFERENCE_ENDPOINT = (
24+
"https://router.huggingface.co/hf-inference/models/{model_name}"
25+
)
26+
27+
1528
@pytest.fixture
1629
def mock_hf_text_generation_api():
1730
# type: () -> Any
@@ -22,7 +35,7 @@ def mock_hf_text_generation_api():
2235
# Mock model info endpoint
2336
rsps.add(
2437
responses.GET,
25-
f"https://huggingface.co/api/models/{model_name}",
38+
MODEL_ENDPOINT.format(model_name=model_name),
2639
json={
2740
"id": model_name,
2841
"pipeline_tag": "text-generation",
@@ -40,7 +53,7 @@ def mock_hf_text_generation_api():
4053
# Mock text generation endpoint
4154
rsps.add(
4255
responses.POST,
43-
f"https://router.huggingface.co/hf-inference/models/{model_name}",
56+
INFERENCE_ENDPOINT.format(model_name=model_name),
4457
json={
4558
"generated_text": "Mocked response",
4659
"details": {
@@ -66,7 +79,7 @@ def mock_hf_chat_completion_api():
6679
# Mock model info endpoint
6780
rsps.add(
6881
responses.GET,
69-
f"https://huggingface.co/api/models/{model_name}",
82+
MODEL_ENDPOINT.format(model_name=model_name),
7083
json={
7184
"id": model_name,
7285
"pipeline_tag": "conversational",
@@ -84,7 +97,7 @@ def mock_hf_chat_completion_api():
8497
# Mock chat completion endpoint
8598
rsps.add(
8699
responses.POST,
87-
f"https://router.huggingface.co/hf-inference/models/{model_name}/v1/chat/completions",
100+
INFERENCE_ENDPOINT.format(model_name=model_name) + "/v1/chat/completions",
88101
json={
89102
"id": "xyz-123",
90103
"created": 1234567890,

0 commit comments

Comments
 (0)