Skip to content

Commit 6d13ec9

Browse files
eliastoWauplingithub-actions[bot]
authored andcommitted
Add OVHcloud AI Endpoints as an Inference Provder (#3541)
* Add OVHcloud AI Endpoints provider * 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 <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c899264 commit 6d13ec9

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 ReplicateImageToImageTask, ReplicateTask, ReplicateTextToImageTask, ReplicateTextToSpeechTask
4344
from .sambanova import SambanovaConversationalTask, SambanovaFeatureExtractionTask
@@ -70,6 +71,7 @@
7071
"novita",
7172
"nscale",
7273
"openai",
74+
"ovhcloud",
7375
"publicai",
7476
"replicate",
7577
"sambanova",
@@ -166,6 +168,9 @@
166168
"openai": {
167169
"conversational": OpenAIConversationalTask(),
168170
},
171+
"ovhcloud": {
172+
"conversational": OVHcloudConversationalTask(),
173+
},
169174
"publicai": {
170175
"conversational": PublicAIConversationalTask(),
171176
},

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
ReplicateImageToImageTask,
@@ -1422,6 +1423,57 @@ def test_prepare_url(self):
14221423
assert helper._prepare_url("sk-XXXXXX", "gpt-4o-mini") == "https://api.openai.com/v1/chat/completions"
14231424

14241425

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

0 commit comments

Comments
 (0)