diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index e6bed1af67..5cbdc758c9 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -132,7 +132,7 @@ class InferenceClient: Note: for better compatibility with OpenAI's client, `model` has been aliased as `base_url`. Those 2 arguments are mutually exclusive. If a URL is passed as `model` or `base_url` for chat completion, the `(/v1)/chat/completions` suffix path will be appended to the URL. provider (`str`, *optional*): - Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`. + Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"hyperfusion"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`. Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers. If model is a URL or `base_url` is passed, then `provider` is not used. token (`str`, *optional*): diff --git a/src/huggingface_hub/inference/_providers/__init__.py b/src/huggingface_hub/inference/_providers/__init__.py index 405087d485..1a7c25a420 100644 --- a/src/huggingface_hub/inference/_providers/__init__.py +++ b/src/huggingface_hub/inference/_providers/__init__.py @@ -26,6 +26,7 @@ HFInferenceTask, ) from .hyperbolic import HyperbolicTextGenerationTask, HyperbolicTextToImageTask +from .hyperfusion import HyperfusionConversationalTask from .nebius import ( NebiusConversationalTask, NebiusFeatureExtractionTask, @@ -53,6 +54,7 @@ "groq", "hf-inference", "hyperbolic", + "hyperfusion", "nebius", "novita", "nscale", @@ -124,6 +126,9 @@ "conversational": HyperbolicTextGenerationTask("conversational"), "text-generation": HyperbolicTextGenerationTask("text-generation"), }, + "hyperfusion": { + "conversational": HyperfusionConversationalTask(), + }, "nebius": { "text-to-image": NebiusTextToImageTask(), "conversational": NebiusConversationalTask(), diff --git a/src/huggingface_hub/inference/_providers/hyperfusion.py b/src/huggingface_hub/inference/_providers/hyperfusion.py new file mode 100644 index 0000000000..4b7026fec1 --- /dev/null +++ b/src/huggingface_hub/inference/_providers/hyperfusion.py @@ -0,0 +1,27 @@ +from typing import Optional + +from huggingface_hub.hf_api import InferenceProviderMapping +from huggingface_hub.inference._providers._common import BaseConversationalTask + + +_PROVIDER = "hyperfusion" +_BASE_URL = "https://api.hyperfusion.io" + + +class HyperfusionConversationalTask(BaseConversationalTask): + def __init__(self): + super().__init__(provider=_PROVIDER, base_url=_BASE_URL) + + def _prepare_api_key(self, api_key: Optional[str]) -> str: + if api_key is None: + raise ValueError( + "You must provide an api_key to work with Hyperfusion API." + ) + return api_key + + def _prepare_mapping_info(self, model: Optional[str]) -> InferenceProviderMapping: + if model is None: + raise ValueError("Please provide an Hyperfusion model ID, e.g. `llm-en`.") + return InferenceProviderMapping( + providerId=model, task="conversational", status="live", hf_model_id=model + ) diff --git a/tests/test_inference_providers.py b/tests/test_inference_providers.py index eea23ed5f4..ab15cb6c0b 100644 --- a/tests/test_inference_providers.py +++ b/tests/test_inference_providers.py @@ -39,6 +39,7 @@ HFInferenceTask, ) from huggingface_hub.inference._providers.hyperbolic import HyperbolicTextGenerationTask, HyperbolicTextToImageTask +from huggingface_hub.inference._providers.hyperfusion import HyperfusionConversationalTask from huggingface_hub.inference._providers.nebius import NebiusFeatureExtractionTask, NebiusTextToImageTask from huggingface_hub.inference._providers.novita import NovitaConversationalTask, NovitaTextGenerationTask from huggingface_hub.inference._providers.nscale import NscaleConversationalTask, NscaleTextToImageTask @@ -910,6 +911,10 @@ def test_text_to_image_get_response(self): response = helper.get_response({"images": [{"image": base64.b64encode(dummy_image).decode()}]}) assert response == dummy_image +class TestHyperfusionProvider: + def test_prepare_url(self): + helper = HyperfusionConversationalTask() + assert helper._prepare_url("sk-XXXXXX", "llm-en") == "https://api.hyperfusion.io/v1/chat/completions" class TestNebiusProvider: def test_prepare_route_text_to_image(self):