@huggingface/inference
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -52,3 +52,11 @@ var __defProp = Object.defineProperty; | ||
"black-forest-labs/FLUX.1-schnell": "fal-ai/flux/schnell", | ||
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev" | ||
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev", | ||
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25", | ||
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models", | ||
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma", | ||
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium", | ||
"Warlord-K/Sana-1024": "fal-ai/sana", | ||
"fal/AuraFlow-v0.2": "fal-ai/aura-flow", | ||
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large", | ||
"Kwai-Kolors/Kolors": "fal-ai/kolors" | ||
}, | ||
@@ -66,6 +74,6 @@ "automatic-speech-recognition": { | ||
"ByteDance/SDXL-Lightning": "bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637" | ||
}, | ||
"text-to-speech": { | ||
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:39a59319327b27327fa3095149c5a746e7f2aee18c75055c3368237a6503cd26" | ||
} | ||
// "text-to-speech": { | ||
// "SWivid/F5-TTS": "x-lance/f5-tts:87faf6dd7a692dd82043f662e76369cab126a2cf1937e25a9d41e0b834fd230e" | ||
// }, | ||
}; | ||
@@ -106,2 +114,4 @@ | ||
"databricks/dbrx-instruct": "databricks/dbrx-instruct", | ||
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1", | ||
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3", | ||
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat", | ||
@@ -152,3 +162,4 @@ "google/gemma-2-9b-it": "google/gemma-2-9b-it", | ||
async function makeRequestOptions(args, options) { | ||
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...otherArgs } = args; | ||
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args; | ||
let otherArgs = remainingArgs; | ||
const provider = maybeProvider ?? "hf-inference"; | ||
@@ -212,5 +223,5 @@ const { forceTask, includeCredentials, taskHint, wait_for_model, use_cache, dont_load_model, chatCompletion: chatCompletion2 } = options ?? {}; | ||
} | ||
if (provider === "replicate" && model.includes(":")) { | ||
const version = model.split(":")[1]; | ||
otherArgs.version = version; | ||
if (provider === "replicate") { | ||
const version = model.includes(":") ? model.split(":")[1] : void 0; | ||
otherArgs = { input: otherArgs, version }; | ||
} | ||
@@ -588,2 +599,15 @@ const info = { | ||
}); | ||
if (res && typeof res === "object") { | ||
if ("output" in res) { | ||
if (typeof res.output === "string") { | ||
const urlResponse = await fetch(res.output); | ||
const blob = await urlResponse.blob(); | ||
return blob; | ||
} else if (Array.isArray(res.output)) { | ||
const urlResponse = await fetch(res.output[0]); | ||
const blob = await urlResponse.blob(); | ||
return blob; | ||
} | ||
} | ||
} | ||
const isValidOutput = res && res instanceof Blob; | ||
@@ -670,6 +694,6 @@ if (!isValidOutput) { | ||
args.prompt = args.inputs; | ||
args.inputs = ""; | ||
delete args.inputs; | ||
args.response_format = "base64"; | ||
} else if (args.provider === "replicate") { | ||
args.input = { prompt: args.inputs }; | ||
args.prompt = args.inputs; | ||
delete args.inputs; | ||
@@ -676,0 +700,0 @@ } |
{ | ||
"name": "@huggingface/inference", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"packageManager": "pnpm@8.10.5", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@huggingface/tasks": "^0.13.16" | ||
"@huggingface/tasks": "^0.13.17" | ||
}, | ||
@@ -45,0 +45,0 @@ "devDependencies": { |
@@ -45,11 +45,11 @@ # 🤗 Hugging Face Inference Endpoints | ||
### Requesting third-party inference providers | ||
### Third-party inference providers | ||
You can request inference from third-party providers with the inference client. | ||
You can send inference requests to third-party providers with the inference client. | ||
Currently, we support the following providers: [Fal.ai](https://fal.ai), [Replicate](https://replicate.com), [Together](https://together.xyz) and [Sambanova](https://sambanova.ai). | ||
To make request to a third-party provider, you have to pass the `provider` parameter to the inference function. Make sure your request is authenticated with an access token. | ||
To send requests to a third-party provider, you have to pass the `provider` parameter to the inference function. Make sure your request is authenticated with an access token. | ||
```ts | ||
const accessToken = "hf_..."; // Either a HF access token, or an API key from the 3rd party provider (Replicate in this example) | ||
const accessToken = "hf_..."; // Either a HF access token, or an API key from the third-party provider (Replicate in this example) | ||
@@ -67,3 +67,3 @@ const client = new HfInference(accessToken); | ||
Only a subset of models are supported when requesting 3rd party providers. You can check the list of supported models per pipeline tasks here: | ||
Only a subset of models are supported when requesting third-party providers. You can check the list of supported models per pipeline tasks here: | ||
- [Fal.ai supported models](./src/providers/fal-ai.ts) | ||
@@ -75,4 +75,9 @@ - [Replicate supported models](./src/providers/replicate.ts) | ||
#### Tree-shaking | ||
❗**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. | ||
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! | ||
👋**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 | ||
### Tree-shaking | ||
You can import the functions you need directly from the module instead of using the `HfInference` class. | ||
@@ -79,0 +84,0 @@ |
@@ -35,3 +35,4 @@ import type { WidgetType } from "@huggingface/tasks"; | ||
): Promise<{ url: string; info: RequestInit }> { | ||
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...otherArgs } = args; | ||
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args; | ||
let otherArgs = remainingArgs; | ||
const provider = maybeProvider ?? "hf-inference"; | ||
@@ -124,8 +125,9 @@ | ||
/* | ||
/** | ||
* Replicate models wrap all inputs inside { input: ... } | ||
* Versioned Replicate models in the format `owner/model:version` expect the version in the body | ||
*/ | ||
if (provider === "replicate" && model.includes(":")) { | ||
const version = model.split(":")[1]; | ||
(otherArgs as typeof otherArgs & { version: string }).version = version; | ||
if (provider === "replicate") { | ||
const version = model.includes(":") ? model.split(":")[1] : undefined; | ||
(otherArgs as unknown) = { input: otherArgs, version }; | ||
} | ||
@@ -132,0 +134,0 @@ |
@@ -11,2 +11,10 @@ import type { ProviderMapping } from "./types"; | ||
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev", | ||
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25", | ||
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models", | ||
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma", | ||
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium", | ||
"Warlord-K/Sana-1024": "fal-ai/sana", | ||
"fal/AuraFlow-v0.2": "fal-ai/aura-flow", | ||
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large", | ||
"Kwai-Kolors/Kolors": "fal-ai/kolors", | ||
}, | ||
@@ -13,0 +21,0 @@ "automatic-speech-recognition": { |
@@ -13,5 +13,5 @@ import type { ProviderMapping } from "./types"; | ||
}, | ||
// "text-to-speech": { | ||
// "SWivid/F5-TTS": "x-lance/f5-tts:87faf6dd7a692dd82043f662e76369cab126a2cf1937e25a9d41e0b834fd230e" | ||
// }, | ||
"text-to-speech": { | ||
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:39a59319327b27327fa3095149c5a746e7f2aee18c75055c3368237a6503cd26", | ||
}, | ||
}; |
@@ -24,2 +24,4 @@ import type { ProviderMapping } from "./types"; | ||
"databricks/dbrx-instruct": "databricks/dbrx-instruct", | ||
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1", | ||
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3", | ||
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat", | ||
@@ -26,0 +28,0 @@ "google/gemma-2-9b-it": "google/gemma-2-9b-it", |
@@ -13,3 +13,5 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError"; | ||
export type TextToSpeechOutput = Blob; | ||
interface OutputUrlTextToSpeechGeneration { | ||
output: string | string[]; | ||
} | ||
/** | ||
@@ -20,6 +22,19 @@ * This task synthesize an audio of a voice pronouncing a given text. | ||
export async function textToSpeech(args: TextToSpeechArgs, options?: Options): Promise<TextToSpeechOutput> { | ||
const res = await request<TextToSpeechOutput>(args, { | ||
const res = await request<TextToSpeechOutput | OutputUrlTextToSpeechGeneration>(args, { | ||
...options, | ||
taskHint: "text-to-speech", | ||
}); | ||
if (res && typeof res === "object") { | ||
if ("output" in res) { | ||
if (typeof res.output === "string") { | ||
const urlResponse = await fetch(res.output); | ||
const blob = await urlResponse.blob(); | ||
return blob; | ||
} else if (Array.isArray(res.output)) { | ||
const urlResponse = await fetch(res.output[0]); | ||
const blob = await urlResponse.blob(); | ||
return blob; | ||
} | ||
} | ||
} | ||
const isValidOutput = res && res instanceof Blob; | ||
@@ -26,0 +41,0 @@ if (!isValidOutput) { |
@@ -62,6 +62,6 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError"; | ||
args.prompt = args.inputs; | ||
args.inputs = ""; | ||
delete (args as unknown as { inputs: unknown }).inputs; | ||
args.response_format = "base64"; | ||
} else if (args.provider === "replicate") { | ||
args.input = { prompt: args.inputs }; | ||
args.prompt = args.inputs; | ||
delete (args as unknown as { inputs: unknown }).inputs; | ||
@@ -68,0 +68,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
284833
6236
662
18
Updated@huggingface/tasks@^0.13.17