Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions docs/source/en/guides/inference.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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"`, `publicai`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"` or `"zai-org"`.
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"clarifai"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `publicai`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"` or `"zai-org"`.
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*):
Expand Down
2 changes: 1 addition & 1 deletion src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class AsyncInferenceClient:
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"`, `publicai`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"` or `"zai-org"`.
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"clarifai"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `publicai`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"` or `"zai-org"`.
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*):
Expand Down
5 changes: 5 additions & 0 deletions src/huggingface_hub/inference/_providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ._common import TaskProviderHelper, _fetch_inference_provider_mapping
from .black_forest_labs import BlackForestLabsTextToImageTask
from .cerebras import CerebrasConversationalTask
from .clarifai import ClarifaiConversationalTask
from .cohere import CohereConversationalTask
from .fal_ai import (
FalAIAutomaticSpeechRecognitionTask,
Expand Down Expand Up @@ -50,6 +51,7 @@
PROVIDER_T = Literal[
"black-forest-labs",
"cerebras",
"clarifai",
"cohere",
"fal-ai",
"featherless-ai",
Expand Down Expand Up @@ -78,6 +80,9 @@
"cerebras": {
"conversational": CerebrasConversationalTask(),
},
"clarifai": {
"conversational": ClarifaiConversationalTask(),
},
"cohere": {
"conversational": CohereConversationalTask(),
},
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/inference/_providers/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# status="live")
"cerebras": {},
"cohere": {},
"clarifai": {},
"fal-ai": {},
"fireworks-ai": {},
"groq": {},
Expand Down
10 changes: 10 additions & 0 deletions src/huggingface_hub/inference/_providers/clarifai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ._common import BaseConversationalTask


_PROVIDER = "clarifai"
_BASE_URL = "https://api.clarifai.com/v2/ext/openai"


class ClarifaiConversationalTask(BaseConversationalTask):
def __init__(self):
super().__init__(provider=_PROVIDER, base_url=_BASE_URL)
29 changes: 29 additions & 0 deletions tests/test_inference_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
recursive_merge,
)
from huggingface_hub.inference._providers.black_forest_labs import BlackForestLabsTextToImageTask
from huggingface_hub.inference._providers.clarifai import ClarifaiConversationalTask
from huggingface_hub.inference._providers.cohere import CohereConversationalTask
from huggingface_hub.inference._providers.fal_ai import (
_POLLING_INTERVAL,
Expand Down Expand Up @@ -293,6 +294,34 @@ def test_prepare_payload_as_dict(self):
}


class TestClarifaiProvider:
def test_prepare_url(self):
helper = ClarifaiConversationalTask()
assert (
helper._prepare_url("clarifai_api_key", "username/repo_name")
== "https://api.clarifai.com/v2/ext/openai/v1/chat/completions"
)

def test_prepare_payload_as_dict(self):
helper = ClarifaiConversationalTask()
payload = helper._prepare_payload_as_dict(
[{"role": "user", "content": "Hello!"}],
{},
InferenceProviderMapping(
provider="clarifai",
hf_model_id="meta-llama/llama-3.1-8B-Instruct",
providerId="meta-llama/llama-3.1-8B-Instruct",
task="conversational",
status="live",
),
)

assert payload == {
"messages": [{"role": "user", "content": "Hello!"}],
"model": "meta-llama/llama-3.1-8B-Instruct",
}


class TestFalAIProvider:
def test_prepare_headers_fal_ai_key(self):
"""When using direct call, must use Key authorization."""
Expand Down
Loading