Skip to content

Commit 45e1474

Browse files
eliastoWauplingithub-actions[bot]
authored
Add OVHcloud AI Endpoints as an Inference Provder (#3541)
* Add OVHcloud AI Endpoints provider # Conflicts: # docs/source/en/guides/inference.md * Only add text-generation and conversational task from feedback * Edit name of class and text-generation * Remove text_generation capability * Apply style fixes --------- Co-authored-by: Lucain <lucain@huggingface.co> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent dd8d310 commit 45e1474

File tree

8 files changed

+104
-33
lines changed

8 files changed

+104
-33
lines changed

docs/source/en/guides/inference.md

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

src/huggingface_hub/inference/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class InferenceClient:
135135
Note: for better compatibility with OpenAI's client, `model` has been aliased as `base_url`. Those 2
136136
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.
137137
provider (`str`, *optional*):
138-
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"`, `"wavespeed"` or `"zai-org"`.
138+
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"`, `"ovhcloud"`, `"publicai"`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"`, `"wavespeed"` or `"zai-org"`.
139139
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.
140140
If model is a URL or `base_url` is passed, then `provider` is not used.
141141
token (`str`, *optional*):

src/huggingface_hub/inference/_generated/_async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class AsyncInferenceClient:
126126
Note: for better compatibility with OpenAI's client, `model` has been aliased as `base_url`. Those 2
127127
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.
128128
provider (`str`, *optional*):
129-
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"`, `"wavespeed"` or `"zai-org"`.
129+
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"`, `"ovhcloud"`, `"publicai"`, `"replicate"`, `"sambanova"`, `"scaleway"`, `"together"`, `"wavespeed"` or `"zai-org"`.
130130
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.
131131
If model is a URL or `base_url` is passed, then `provider` is not used.
132132
token (`str`, *optional*):

src/huggingface_hub/inference/_providers/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .novita import NovitaConversationalTask, NovitaTextGenerationTask, NovitaTextToVideoTask
3939
from .nscale import NscaleConversationalTask, NscaleTextToImageTask
4040
from .openai import OpenAIConversationalTask
41+
from .ovhcloud import OVHcloudConversationalTask
4142
from .publicai import PublicAIConversationalTask
4243
from .replicate import (
4344
ReplicateAutomaticSpeechRecognitionTask,
@@ -76,6 +77,7 @@
7677
"novita",
7778
"nscale",
7879
"openai",
80+
"ovhcloud",
7981
"publicai",
8082
"replicate",
8183
"sambanova",
@@ -172,6 +174,9 @@
172174
"openai": {
173175
"conversational": OpenAIConversationalTask(),
174176
},
177+
"ovhcloud": {
178+
"conversational": OVHcloudConversationalTask(),
179+
},
175180
"publicai": {
176181
"conversational": PublicAIConversationalTask(),
177182
},

src/huggingface_hub/inference/_providers/_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"hyperbolic": {},
3333
"nebius": {},
3434
"nscale": {},
35+
"ovhcloud": {},
3536
"replicate": {},
3637
"sambanova": {},
3738
"scaleway": {},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from huggingface_hub.inference._providers._common import BaseConversationalTask
2+
3+
4+
_PROVIDER = "ovhcloud"
5+
_BASE_URL = "https://oai.endpoints.kepler.ai.cloud.ovh.net"
6+
7+
8+
class OVHcloudConversationalTask(BaseConversationalTask):
9+
def __init__(self):
10+
super().__init__(provider=_PROVIDER, base_url=_BASE_URL)

tests/test_inference_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
"text-generation": "NousResearch/Nous-Hermes-Llama2-13b",
118118
"conversational": "meta-llama/Llama-3.1-8B-Instruct",
119119
},
120+
"ovhcloud": {
121+
"conversational": "meta-llama/Llama-3.1-8B-Instruct",
122+
},
120123
"replicate": {
121124
"text-to-image": "ByteDance/SDXL-Lightning",
122125
},

tests/test_inference_providers.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from huggingface_hub.inference._providers.novita import NovitaConversationalTask, NovitaTextGenerationTask
4747
from huggingface_hub.inference._providers.nscale import NscaleConversationalTask, NscaleTextToImageTask
4848
from huggingface_hub.inference._providers.openai import OpenAIConversationalTask
49+
from huggingface_hub.inference._providers.ovhcloud import OVHcloudConversationalTask
4950
from huggingface_hub.inference._providers.publicai import PublicAIConversationalTask
5051
from huggingface_hub.inference._providers.replicate import (
5152
ReplicateAutomaticSpeechRecognitionTask,
@@ -1423,6 +1424,57 @@ def test_prepare_url(self):
14231424
assert helper._prepare_url("sk-XXXXXX", "gpt-4o-mini") == "https://api.openai.com/v1/chat/completions"
14241425

14251426

1427+
class TestOVHcloudAIEndpointsProvider:
1428+
def test_prepare_hf_url_conversational(self):
1429+
helper = OVHcloudConversationalTask()
1430+
url = helper._prepare_url("hf_token", "username/repo_name")
1431+
assert url == "https://router.huggingface.co/ovhcloud/v1/chat/completions"
1432+
1433+
def test_prepare_url_conversational(self):
1434+
helper = OVHcloudConversationalTask()
1435+
url = helper._prepare_url("ovhcloud_token", "username/repo_name")
1436+
assert url == "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/chat/completions"
1437+
1438+
def test_prepare_payload_as_dict(self):
1439+
helper = OVHcloudConversationalTask()
1440+
payload = helper._prepare_payload_as_dict(
1441+
[
1442+
{"role": "system", "content": "You are a helpful assistant"},
1443+
{"role": "user", "content": "Hello!"},
1444+
],
1445+
{
1446+
"max_tokens": 512,
1447+
"temperature": 0.15,
1448+
"top_p": 1,
1449+
"presence_penalty": 0,
1450+
"stream": True,
1451+
},
1452+
InferenceProviderMapping(
1453+
provider="ovhcloud",
1454+
hf_model_id="meta-llama/Llama-3.1-8B-Instruct",
1455+
providerId="Llama-3.1-8B-Instruct",
1456+
task="conversational",
1457+
status="live",
1458+
),
1459+
)
1460+
assert payload == {
1461+
"max_tokens": 512,
1462+
"messages": [
1463+
{"content": "You are a helpful assistant", "role": "system"},
1464+
{"role": "user", "content": "Hello!"},
1465+
],
1466+
"model": "Llama-3.1-8B-Instruct",
1467+
"presence_penalty": 0,
1468+
"stream": True,
1469+
"temperature": 0.15,
1470+
"top_p": 1,
1471+
}
1472+
1473+
def test_prepare_route_conversational(self):
1474+
helper = OVHcloudConversationalTask()
1475+
assert helper._prepare_route("username/repo_name", "hf_token") == "/v1/chat/completions"
1476+
1477+
14261478
class TestReplicateProvider:
14271479
def test_automatic_speech_recognition_payload(self):
14281480
helper = ReplicateAutomaticSpeechRecognitionTask()

0 commit comments

Comments
 (0)