-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nebius AI Studio provider added (#2866)
* Nebius provider added * nebius occurance sorted alphabetically * nebius text-to-image task fixed; tests for nebius provider added * upload cassettes and update docs * maintain alphabetical order * fix merging * height and width are not required * Update docs/source/en/guides/inference.md --------- Co-authored-by: Akim Tsvigun <[email protected]> Co-authored-by: Celina Hanouti <[email protected]> Co-authored-by: Lucain <[email protected]>
- Loading branch information
1 parent
604b9ca
commit ace6668
Showing
11 changed files
with
533 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import base64 | ||
from typing import Any, Dict, Optional, Union | ||
|
||
from huggingface_hub.inference._common import _as_dict | ||
from huggingface_hub.inference._providers._common import ( | ||
BaseConversationalTask, | ||
BaseTextGenerationTask, | ||
TaskProviderHelper, | ||
filter_none, | ||
) | ||
|
||
|
||
class NebiusTextGenerationTask(BaseTextGenerationTask): | ||
def __init__(self): | ||
super().__init__(provider="nebius", base_url="https://api.studio.nebius.ai") | ||
|
||
|
||
class NebiusConversationalTask(BaseConversationalTask): | ||
def __init__(self): | ||
super().__init__(provider="nebius", base_url="https://api.studio.nebius.ai") | ||
|
||
|
||
class NebiusTextToImageTask(TaskProviderHelper): | ||
def __init__(self): | ||
super().__init__(task="text-to-image", provider="nebius", base_url="https://api.studio.nebius.ai") | ||
|
||
def _prepare_route(self, mapped_model: str) -> str: | ||
return "/v1/images/generations" | ||
|
||
def _prepare_payload_as_dict(self, inputs: Any, parameters: Dict, mapped_model: str) -> Optional[Dict]: | ||
parameters = filter_none(parameters) | ||
if "guidance_scale" in parameters: | ||
parameters.pop("guidance_scale") | ||
if parameters.get("response_format") not in ("b64_json", "url"): | ||
parameters["response_format"] = "b64_json" | ||
|
||
return {"prompt": inputs, **parameters, "model": mapped_model} | ||
|
||
def get_response(self, response: Union[bytes, Dict]) -> Any: | ||
response_dict = _as_dict(response) | ||
return base64.b64decode(response_dict["data"][0]["b64_json"]) |
Oops, something went wrong.