Skip to content

Commit f704e07

Browse files
committed
Merge branch 'main' into saksham/blackforestlabs-ai
2 parents 956050f + a32260f commit f704e07

File tree

18 files changed

+323
-82
lines changed

18 files changed

+323
-82
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
env:
4343
HF_TOKEN: ${{ secrets.HF_TOKEN }}
4444
HF_FAL_KEY: dummy
45+
HF_NEBIUS_KEY: dummy
4546
HF_REPLICATE_KEY: dummy
4647
HF_SAMBANOVA_KEY: dummy
4748
HF_TOGETHER_KEY: dummy
@@ -84,6 +85,7 @@ jobs:
8485
env:
8586
HF_TOKEN: ${{ secrets.HF_TOKEN }}
8687
HF_FAL_KEY: dummy
88+
HF_NEBIUS_KEY: dummy
8789
HF_REPLICATE_KEY: dummy
8890
HF_SAMBANOVA_KEY: dummy
8991
HF_TOGETHER_KEY: dummy
@@ -153,6 +155,7 @@ jobs:
153155
NPM_CONFIG_REGISTRY: http://localhost:4874/
154156
HF_TOKEN: ${{ secrets.HF_TOKEN }}
155157
HF_FAL_KEY: dummy
158+
HF_NEBIUS_KEY: dummy
156159
HF_REPLICATE_KEY: dummy
157160
HF_SAMBANOVA_KEY: dummy
158161
HF_TOGETHER_KEY: dummy

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
9696

9797
```html
9898
<script type="module">
99-
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected].0/+esm';
99+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected].3/+esm';
100100
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
101101
</script>
102102
```

packages/agents/src/tools/imageToText.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ export const imageToTextTool: Tool = {
1515
if (typeof data === "string") throw "Input must be a blob.";
1616

1717
return (
18-
await inference.imageToText(
19-
{
20-
data,
21-
},
22-
{ wait_for_model: true }
23-
)
18+
await inference.imageToText({
19+
data,
20+
})
2421
).generated_text;
2522
},
2623
};

packages/agents/src/tools/speechToText.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ export const speechToTextTool: Tool = {
1515
if (typeof data === "string") throw "Input must be a blob.";
1616

1717
return (
18-
await inference.automaticSpeechRecognition(
19-
{
20-
data,
21-
},
22-
{ wait_for_model: true }
23-
)
18+
await inference.automaticSpeechRecognition({
19+
data,
20+
})
2421
).text;
2522
},
2623
};

packages/agents/src/tools/textToImage.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ export const textToImageTool: Tool = {
1919
const data = await input;
2020
if (typeof data !== "string") throw "Input must be a string.";
2121

22-
return await inference.textToImage(
23-
{
24-
inputs: data,
25-
},
26-
{ wait_for_model: true }
27-
);
22+
return await inference.textToImage({
23+
inputs: data,
24+
});
2825
},
2926
};

packages/agents/src/tools/textToSpeech.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ export const textToSpeechTool: Tool = {
1919
const data = await input;
2020
if (typeof data !== "string") throw "Input must be a string.";
2121

22-
return inference.textToSpeech(
23-
{
24-
inputs: data,
25-
model: "espnet/kan-bayashi_ljspeech_vits",
26-
},
27-
{ wait_for_model: true }
28-
);
22+
return inference.textToSpeech({
23+
inputs: data,
24+
model: "espnet/kan-bayashi_ljspeech_vits",
25+
});
2926
},
3027
};

packages/inference/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ You can send inference requests to third-party providers with the inference clie
4949
Currently, we support the following providers:
5050
- [Fal.ai](https://fal.ai)
5151
- [Fireworks AI](https://fireworks.ai)
52+
- [Nebius](https://studio.nebius.ai)
5253
- [Replicate](https://replicate.com)
5354
- [Sambanova](https://sambanova.ai)
5455
- [Together](https://together.xyz)
@@ -72,12 +73,13 @@ When authenticated with a third-party provider key, the request is made directly
7273
Only a subset of models are supported when requesting third-party providers. You can check the list of supported models per pipeline tasks here:
7374
- [Fal.ai supported models](https://huggingface.co/api/partners/fal-ai/models)
7475
- [Fireworks AI supported models](https://huggingface.co/api/partners/fireworks-ai/models)
76+
- [Nebius supported models](https://huggingface.co/api/partners/nebius/models)
7577
- [Replicate supported models](https://huggingface.co/api/partners/replicate/models)
7678
- [Sambanova supported models](https://huggingface.co/api/partners/sambanova/models)
7779
- [Together supported models](https://huggingface.co/api/partners/together/models)
7880
- [HF Inference API (serverless)](https://huggingface.co/models?inference=warm&sort=trending)
7981

80-
**Important note:** To be compatible, the third-party API must adhere to the "standard" shape API we expect on HF model pages for each pipeline task type.
82+
**Important note:** To be compatible, the third-party API must adhere to the "standard" shape API we expect on HF model pages for each pipeline task type.
8183
This is not an issue for LLMs as everyone converged on the OpenAI API anyways, but can be more tricky for other tasks like "text-to-image" or "automatic-speech-recognition" where there exists no standard API. Let us know if any help is needed or if we can make things easier for you!
8284

8385
👋**Want to add another provider?** Get in touch if you'd like to add support for another Inference provider, and/or request it on https://huggingface.co/spaces/huggingface/HuggingDiscussions/discussions/49
@@ -464,7 +466,7 @@ await hf.zeroShotImageClassification({
464466
model: 'openai/clip-vit-large-patch14-336',
465467
inputs: {
466468
image: await (await fetch('https://placekitten.com/300/300')).blob()
467-
},
469+
},
468470
parameters: {
469471
candidate_labels: ['cat', 'dog']
470472
}

packages/inference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@huggingface/inference",
3-
"version": "3.3.0",
3+
"version": "3.3.3",
44
"packageManager": "[email protected]",
55
"license": "MIT",
66
"author": "Tim Mikeladze <[email protected]>",

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
22
import { FAL_AI_API_BASE_URL } from "../providers/fal-ai";
3+
import { NEBIUS_API_BASE_URL } from "../providers/nebius";
34
import { REPLICATE_API_BASE_URL } from "../providers/replicate";
45
import { SAMBANOVA_API_BASE_URL } from "../providers/sambanova";
56
import { TOGETHER_API_BASE_URL } from "../providers/together";
@@ -39,8 +40,7 @@ export async function makeRequestOptions(
3940
let otherArgs = remainingArgs;
4041
const provider = maybeProvider ?? "hf-inference";
4142

42-
const { forceTask, includeCredentials, taskHint, wait_for_model, use_cache, dont_load_model, chatCompletion } =
43-
options ?? {};
43+
const { forceTask, includeCredentials, taskHint, chatCompletion } = options ?? {};
4444

4545
if (endpointUrl && provider !== "hf-inference") {
4646
throw new Error(`Cannot use endpointUrl with a third-party provider.`);
@@ -107,18 +107,6 @@ export async function makeRequestOptions(
107107
headers["Content-Type"] = "application/json";
108108
}
109109

110-
if (provider === "hf-inference") {
111-
if (wait_for_model) {
112-
headers["X-Wait-For-Model"] = "true";
113-
}
114-
if (use_cache === false) {
115-
headers["X-Use-Cache"] = "false";
116-
}
117-
if (dont_load_model) {
118-
headers["X-Load-Model"] = "0";
119-
}
120-
}
121-
122110
if (provider === "replicate") {
123111
headers["Prefer"] = "wait";
124112
}
@@ -149,7 +137,7 @@ export async function makeRequestOptions(
149137
? args.data
150138
: JSON.stringify({
151139
...otherArgs,
152-
...(chatCompletion || provider === "together" ? { model } : undefined),
140+
...(chatCompletion || provider === "together" || provider === "nebius" ? { model } : undefined),
153141
}),
154142
...(credentials ? { credentials } : undefined),
155143
signal: options?.signal,
@@ -184,6 +172,22 @@ function makeUrl(params: {
184172
: FAL_AI_API_BASE_URL;
185173
return `${baseUrl}/${params.model}`;
186174
}
175+
case "nebius": {
176+
const baseUrl = shouldProxy
177+
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
178+
: NEBIUS_API_BASE_URL;
179+
180+
if (params.taskHint === "text-to-image") {
181+
return `${baseUrl}/v1/images/generations`;
182+
}
183+
if (params.taskHint === "text-generation") {
184+
if (params.chatCompletion) {
185+
return `${baseUrl}/v1/chat/completions`;
186+
}
187+
return `${baseUrl}/v1/completions`;
188+
}
189+
return baseUrl;
190+
}
187191
case "replicate": {
188192
const baseUrl = shouldProxy
189193
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)

packages/inference/src/providers/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const HARDCODED_MODEL_ID_MAPPING: Record<InferenceProvider, Record<ModelI
2020
"fal-ai": {},
2121
"fireworks-ai": {},
2222
"hf-inference": {},
23+
nebius: {},
2324
replicate: {},
2425
sambanova: {},
2526
together: {},

0 commit comments

Comments
 (0)