@huggingface/inference 3.1.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.cjs +69 -153
- package/dist/index.js +69 -149
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/lib/getProviderModelId.d.ts +10 -0
- package/dist/src/lib/getProviderModelId.d.ts.map +1 -0
- package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/src/providers/consts.d.ts +10 -0
- package/dist/src/providers/consts.d.ts.map +1 -0
- package/dist/src/providers/fal-ai.d.ts +16 -4
- package/dist/src/providers/fal-ai.d.ts.map +1 -1
- package/dist/src/providers/replicate.d.ts +16 -4
- package/dist/src/providers/replicate.d.ts.map +1 -1
- package/dist/src/providers/sambanova.d.ts +16 -4
- package/dist/src/providers/sambanova.d.ts.map +1 -1
- package/dist/src/providers/together.d.ts +14 -8
- package/dist/src/providers/together.d.ts.map +1 -1
- package/dist/src/tasks/audio/textToSpeech.d.ts.map +1 -1
- package/dist/src/types.d.ts +3 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/test/HfInference.spec.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +1 -0
- package/src/index.ts +0 -5
- package/src/lib/getProviderModelId.ts +74 -0
- package/src/lib/makeRequestOptions.ts +16 -51
- package/src/providers/consts.ts +15 -0
- package/src/providers/fal-ai.ts +16 -29
- package/src/providers/replicate.ts +16 -27
- package/src/providers/sambanova.ts +16 -21
- package/src/providers/together.ts +14 -55
- package/src/tasks/audio/textToSpeech.ts +11 -2
- package/src/types.ts +2 -2
- package/dist/src/providers/types.d.ts +0 -4
- package/dist/src/providers/types.d.ts.map +0 -1
- package/src/providers/types.ts +0 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🤗 Hugging Face Inference
|
|
2
2
|
|
|
3
|
-
A Typescript powered wrapper for the
|
|
3
|
+
A Typescript powered wrapper for the HF Inference API (serverless), Inference Endpoints (dedicated), and third-party Inference Providers.
|
|
4
4
|
It works with [Inference API (serverless)](https://huggingface.co/docs/api-inference/index) and [Inference Endpoints (dedicated)](https://huggingface.co/docs/inference-endpoints/index), and even with supported third-party Inference Providers.
|
|
5
5
|
|
|
6
6
|
Check out the [full documentation](https://huggingface.co/docs/huggingface.js/inference/README).
|
|
@@ -117,7 +117,7 @@ for await (const output of hf.textGenerationStream({
|
|
|
117
117
|
|
|
118
118
|
### Text Generation (Chat Completion API Compatible)
|
|
119
119
|
|
|
120
|
-
Using the `chatCompletion` method, you can generate text with models compatible with the OpenAI Chat Completion API. All models served by [TGI](https://
|
|
120
|
+
Using the `chatCompletion` method, you can generate text with models compatible with the OpenAI Chat Completion API. All models served by [TGI](https://huggingface.co/docs/text-generation-inference/) on Hugging Face support Messages API.
|
|
121
121
|
|
|
122
122
|
[Demo](https://huggingface.co/spaces/huggingfacejs/streaming-chat-completion)
|
|
123
123
|
|
|
@@ -611,7 +611,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
|
|
|
611
611
|
|
|
612
612
|
// Chat Completion Example
|
|
613
613
|
const ep = hf.endpoint(
|
|
614
|
-
"https://
|
|
614
|
+
"https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.1-8B-Instruct"
|
|
615
615
|
);
|
|
616
616
|
const stream = ep.chatCompletionStream({
|
|
617
617
|
model: "tgi",
|
package/dist/index.cjs
CHANGED
|
@@ -20,14 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
FAL_AI_SUPPORTED_MODEL_IDS: () => FAL_AI_SUPPORTED_MODEL_IDS,
|
|
24
23
|
HfInference: () => HfInference,
|
|
25
24
|
HfInferenceEndpoint: () => HfInferenceEndpoint,
|
|
26
25
|
INFERENCE_PROVIDERS: () => INFERENCE_PROVIDERS,
|
|
27
26
|
InferenceOutputError: () => InferenceOutputError,
|
|
28
|
-
REPLICATE_SUPPORTED_MODEL_IDS: () => REPLICATE_SUPPORTED_MODEL_IDS,
|
|
29
|
-
SAMBANOVA_SUPPORTED_MODEL_IDS: () => SAMBANOVA_SUPPORTED_MODEL_IDS,
|
|
30
|
-
TOGETHER_SUPPORTED_MODEL_IDS: () => TOGETHER_SUPPORTED_MODEL_IDS,
|
|
31
27
|
audioClassification: () => audioClassification,
|
|
32
28
|
audioToAudio: () => audioToAudio,
|
|
33
29
|
automaticSpeechRecognition: () => automaticSpeechRecognition,
|
|
@@ -102,126 +98,19 @@ __export(tasks_exports, {
|
|
|
102
98
|
|
|
103
99
|
// src/config.ts
|
|
104
100
|
var HF_HUB_URL = "https://huggingface.co";
|
|
101
|
+
var HF_ROUTER_URL = "https://router.huggingface.co";
|
|
105
102
|
|
|
106
103
|
// src/providers/fal-ai.ts
|
|
107
104
|
var FAL_AI_API_BASE_URL = "https://fal.run";
|
|
108
|
-
var FAL_AI_SUPPORTED_MODEL_IDS = {
|
|
109
|
-
"text-to-image": {
|
|
110
|
-
"black-forest-labs/FLUX.1-schnell": "fal-ai/flux/schnell",
|
|
111
|
-
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev",
|
|
112
|
-
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25",
|
|
113
|
-
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models",
|
|
114
|
-
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma",
|
|
115
|
-
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium",
|
|
116
|
-
"Warlord-K/Sana-1024": "fal-ai/sana",
|
|
117
|
-
"fal/AuraFlow-v0.2": "fal-ai/aura-flow",
|
|
118
|
-
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large",
|
|
119
|
-
"stabilityai/stable-diffusion-3.5-large-turbo": "fal-ai/stable-diffusion-v35-large/turbo",
|
|
120
|
-
"stabilityai/stable-diffusion-3.5-medium": "fal-ai/stable-diffusion-v35-medium",
|
|
121
|
-
"Kwai-Kolors/Kolors": "fal-ai/kolors"
|
|
122
|
-
},
|
|
123
|
-
"automatic-speech-recognition": {
|
|
124
|
-
"openai/whisper-large-v3": "fal-ai/whisper"
|
|
125
|
-
},
|
|
126
|
-
"text-to-video": {
|
|
127
|
-
"genmo/mochi-1-preview": "fal-ai/mochi-v1",
|
|
128
|
-
"tencent/HunyuanVideo": "fal-ai/hunyuan-video",
|
|
129
|
-
"THUDM/CogVideoX-5b": "fal-ai/cogvideox-5b",
|
|
130
|
-
"Lightricks/LTX-Video": "fal-ai/ltx-video"
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
105
|
|
|
134
106
|
// src/providers/replicate.ts
|
|
135
107
|
var REPLICATE_API_BASE_URL = "https://api.replicate.com";
|
|
136
|
-
var REPLICATE_SUPPORTED_MODEL_IDS = {
|
|
137
|
-
"text-to-image": {
|
|
138
|
-
"black-forest-labs/FLUX.1-dev": "black-forest-labs/flux-dev",
|
|
139
|
-
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/flux-schnell",
|
|
140
|
-
"ByteDance/Hyper-SD": "bytedance/hyper-flux-16step:382cf8959fb0f0d665b26e7e80b8d6dc3faaef1510f14ce017e8c732bb3d1eb7",
|
|
141
|
-
"ByteDance/SDXL-Lightning": "bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637",
|
|
142
|
-
"playgroundai/playground-v2.5-1024px-aesthetic": "playgroundai/playground-v2.5-1024px-aesthetic:a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24",
|
|
143
|
-
"stabilityai/stable-diffusion-3.5-large-turbo": "stability-ai/stable-diffusion-3.5-large-turbo",
|
|
144
|
-
"stabilityai/stable-diffusion-3.5-large": "stability-ai/stable-diffusion-3.5-large",
|
|
145
|
-
"stabilityai/stable-diffusion-3.5-medium": "stability-ai/stable-diffusion-3.5-medium",
|
|
146
|
-
"stabilityai/stable-diffusion-xl-base-1.0": "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc"
|
|
147
|
-
},
|
|
148
|
-
"text-to-speech": {
|
|
149
|
-
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:39a59319327b27327fa3095149c5a746e7f2aee18c75055c3368237a6503cd26"
|
|
150
|
-
},
|
|
151
|
-
"text-to-video": {
|
|
152
|
-
"genmo/mochi-1-preview": "genmoai/mochi-1:1944af04d098ef69bed7f9d335d102e652203f268ec4aaa2d836f6217217e460"
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
108
|
|
|
156
109
|
// src/providers/sambanova.ts
|
|
157
110
|
var SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
|
|
158
|
-
var SAMBANOVA_SUPPORTED_MODEL_IDS = {
|
|
159
|
-
/** Chat completion / conversational */
|
|
160
|
-
conversational: {
|
|
161
|
-
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
|
|
162
|
-
"Qwen/Qwen2.5-72B-Instruct": "Qwen2.5-72B-Instruct",
|
|
163
|
-
"Qwen/QwQ-32B-Preview": "QwQ-32B-Preview",
|
|
164
|
-
"meta-llama/Llama-3.3-70B-Instruct": "Meta-Llama-3.3-70B-Instruct",
|
|
165
|
-
"meta-llama/Llama-3.2-1B-Instruct": "Meta-Llama-3.2-1B-Instruct",
|
|
166
|
-
"meta-llama/Llama-3.2-3B-Instruct": "Meta-Llama-3.2-3B-Instruct",
|
|
167
|
-
"meta-llama/Llama-3.2-11B-Vision-Instruct": "Llama-3.2-11B-Vision-Instruct",
|
|
168
|
-
"meta-llama/Llama-3.2-90B-Vision-Instruct": "Llama-3.2-90B-Vision-Instruct",
|
|
169
|
-
"meta-llama/Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
|
|
170
|
-
"meta-llama/Llama-3.1-70B-Instruct": "Meta-Llama-3.1-70B-Instruct",
|
|
171
|
-
"meta-llama/Llama-3.1-405B-Instruct": "Meta-Llama-3.1-405B-Instruct",
|
|
172
|
-
"meta-llama/Llama-Guard-3-8B": "Meta-Llama-Guard-3-8B"
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
111
|
|
|
176
112
|
// src/providers/together.ts
|
|
177
113
|
var TOGETHER_API_BASE_URL = "https://api.together.xyz";
|
|
178
|
-
var TOGETHER_SUPPORTED_MODEL_IDS = {
|
|
179
|
-
"text-to-image": {
|
|
180
|
-
"black-forest-labs/FLUX.1-Canny-dev": "black-forest-labs/FLUX.1-canny",
|
|
181
|
-
"black-forest-labs/FLUX.1-Depth-dev": "black-forest-labs/FLUX.1-depth",
|
|
182
|
-
"black-forest-labs/FLUX.1-dev": "black-forest-labs/FLUX.1-dev",
|
|
183
|
-
"black-forest-labs/FLUX.1-Redux-dev": "black-forest-labs/FLUX.1-redux",
|
|
184
|
-
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/FLUX.1-pro",
|
|
185
|
-
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0"
|
|
186
|
-
},
|
|
187
|
-
conversational: {
|
|
188
|
-
"databricks/dbrx-instruct": "databricks/dbrx-instruct",
|
|
189
|
-
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1",
|
|
190
|
-
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3",
|
|
191
|
-
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat",
|
|
192
|
-
"google/gemma-2-9b-it": "google/gemma-2-9b-it",
|
|
193
|
-
"google/gemma-2b-it": "google/gemma-2-27b-it",
|
|
194
|
-
"meta-llama/Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
|
|
195
|
-
"meta-llama/Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
|
|
196
|
-
"meta-llama/Llama-3.2-11B-Vision-Instruct": "meta-llama/Llama-Vision-Free",
|
|
197
|
-
"meta-llama/Llama-3.2-3B-Instruct": "meta-llama/Llama-3.2-3B-Instruct-Turbo",
|
|
198
|
-
"meta-llama/Llama-3.2-90B-Vision-Instruct": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
|
|
199
|
-
"meta-llama/Llama-3.3-70B-Instruct": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
200
|
-
"meta-llama/Meta-Llama-3-70B-Instruct": "meta-llama/Llama-3-70b-chat-hf",
|
|
201
|
-
"meta-llama/Meta-Llama-3-8B-Instruct": "meta-llama/Meta-Llama-3-8B-Instruct-Turbo",
|
|
202
|
-
"meta-llama/Meta-Llama-3.1-405B-Instruct": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
|
|
203
|
-
"meta-llama/Meta-Llama-3.1-70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
|
|
204
|
-
"meta-llama/Meta-Llama-3.1-8B-Instruct": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo-128K",
|
|
205
|
-
"microsoft/WizardLM-2-8x22B": "microsoft/WizardLM-2-8x22B",
|
|
206
|
-
"mistralai/Mistral-7B-Instruct-v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
|
|
207
|
-
"mistralai/Mistral-Small-24B-Instruct-2501": "mistralai/Mistral-Small-24B-Instruct-2501",
|
|
208
|
-
"mistralai/Mixtral-8x22B-Instruct-v0.1": "mistralai/Mixtral-8x22B-Instruct-v0.1",
|
|
209
|
-
"mistralai/Mixtral-8x7B-Instruct-v0.1": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
210
|
-
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
|
211
|
-
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
|
|
212
|
-
"Qwen/Qwen2-72B-Instruct": "Qwen/Qwen2-72B-Instruct",
|
|
213
|
-
"Qwen/Qwen2.5-72B-Instruct": "Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
214
|
-
"Qwen/Qwen2.5-7B-Instruct": "Qwen/Qwen2.5-7B-Instruct-Turbo",
|
|
215
|
-
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
216
|
-
"Qwen/QwQ-32B-Preview": "Qwen/QwQ-32B-Preview",
|
|
217
|
-
"scb10x/llama-3-typhoon-v1.5-8b-instruct": "scb10x/scb10x-llama3-typhoon-v1-5-8b-instruct",
|
|
218
|
-
"scb10x/llama-3-typhoon-v1.5x-70b-instruct-awq": "scb10x/scb10x-llama3-typhoon-v1-5x-4f316"
|
|
219
|
-
},
|
|
220
|
-
"text-generation": {
|
|
221
|
-
"meta-llama/Llama-2-70b-hf": "meta-llama/Llama-2-70b-hf",
|
|
222
|
-
"mistralai/Mixtral-8x7B-v0.1": "mistralai/Mixtral-8x7B-v0.1"
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
114
|
|
|
226
115
|
// src/lib/isUrl.ts
|
|
227
116
|
function isUrl(modelOrUrl) {
|
|
@@ -230,10 +119,62 @@ function isUrl(modelOrUrl) {
|
|
|
230
119
|
|
|
231
120
|
// package.json
|
|
232
121
|
var name = "@huggingface/inference";
|
|
233
|
-
var version = "3.
|
|
122
|
+
var version = "3.2.0";
|
|
123
|
+
|
|
124
|
+
// src/providers/consts.ts
|
|
125
|
+
var HARDCODED_MODEL_ID_MAPPING = {
|
|
126
|
+
/**
|
|
127
|
+
* "HF model ID" => "Model ID on Inference Provider's side"
|
|
128
|
+
*/
|
|
129
|
+
// "Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/lib/getProviderModelId.ts
|
|
133
|
+
var inferenceProviderMappingCache = /* @__PURE__ */ new Map();
|
|
134
|
+
async function getProviderModelId(params, args, options = {}) {
|
|
135
|
+
if (params.provider === "hf-inference") {
|
|
136
|
+
return params.model;
|
|
137
|
+
}
|
|
138
|
+
if (!options.taskHint) {
|
|
139
|
+
throw new Error("taskHint must be specified when using a third-party provider");
|
|
140
|
+
}
|
|
141
|
+
const task = options.taskHint === "text-generation" && options.chatCompletion ? "conversational" : options.taskHint;
|
|
142
|
+
if (HARDCODED_MODEL_ID_MAPPING[params.model]) {
|
|
143
|
+
return HARDCODED_MODEL_ID_MAPPING[params.model];
|
|
144
|
+
}
|
|
145
|
+
let inferenceProviderMapping;
|
|
146
|
+
if (inferenceProviderMappingCache.has(params.model)) {
|
|
147
|
+
inferenceProviderMapping = inferenceProviderMappingCache.get(params.model);
|
|
148
|
+
} else {
|
|
149
|
+
inferenceProviderMapping = await (options?.fetch ?? fetch)(
|
|
150
|
+
`${HF_HUB_URL}/api/models/${params.model}?expand[]=inferenceProviderMapping`,
|
|
151
|
+
{
|
|
152
|
+
headers: args.accessToken?.startsWith("hf_") ? { Authorization: `Bearer ${args.accessToken}` } : {}
|
|
153
|
+
}
|
|
154
|
+
).then((resp) => resp.json()).then((json) => json.inferenceProviderMapping).catch(() => null);
|
|
155
|
+
}
|
|
156
|
+
if (!inferenceProviderMapping) {
|
|
157
|
+
throw new Error(`We have not been able to find inference provider information for model ${params.model}.`);
|
|
158
|
+
}
|
|
159
|
+
const providerMapping = inferenceProviderMapping[params.provider];
|
|
160
|
+
if (providerMapping) {
|
|
161
|
+
if (providerMapping.task !== task) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Model ${params.model} is not supported for task ${task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (providerMapping.status === "staging") {
|
|
167
|
+
console.warn(
|
|
168
|
+
`Model ${params.model} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return providerMapping.providerId;
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`Model ${params.model} is not supported provider ${params.provider}.`);
|
|
174
|
+
}
|
|
234
175
|
|
|
235
176
|
// src/lib/makeRequestOptions.ts
|
|
236
|
-
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${
|
|
177
|
+
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;
|
|
237
178
|
var tasks = null;
|
|
238
179
|
async function makeRequestOptions(args, options) {
|
|
239
180
|
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args;
|
|
@@ -249,16 +190,15 @@ async function makeRequestOptions(args, options) {
|
|
|
249
190
|
if (maybeModel && isUrl(maybeModel)) {
|
|
250
191
|
throw new Error(`Model URLs are no longer supported. Use endpointUrl instead.`);
|
|
251
192
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (taskHint) {
|
|
255
|
-
model = mapModel({ model: await loadDefaultModel(taskHint), provider, taskHint, chatCompletion: chatCompletion2 });
|
|
256
|
-
} else {
|
|
257
|
-
throw new Error("No model provided, and no default model found for this task");
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
model = mapModel({ model: maybeModel, provider, taskHint, chatCompletion: chatCompletion2 });
|
|
193
|
+
if (!maybeModel && !taskHint) {
|
|
194
|
+
throw new Error("No model provided, and no task has been specified.");
|
|
261
195
|
}
|
|
196
|
+
const hfModel = maybeModel ?? await loadDefaultModel(taskHint);
|
|
197
|
+
const model = await getProviderModelId({ model: hfModel, provider }, args, {
|
|
198
|
+
taskHint,
|
|
199
|
+
chatCompletion: chatCompletion2,
|
|
200
|
+
fetch: options?.fetch
|
|
201
|
+
});
|
|
262
202
|
const authMethod = accessToken ? accessToken.startsWith("hf_") ? "hf-token" : "provider-key" : includeCredentials === "include" ? "credentials-include" : "none";
|
|
263
203
|
const url = endpointUrl ? chatCompletion2 ? endpointUrl + `/v1/chat/completions` : endpointUrl : makeUrl({
|
|
264
204
|
authMethod,
|
|
@@ -314,31 +254,6 @@ async function makeRequestOptions(args, options) {
|
|
|
314
254
|
};
|
|
315
255
|
return { url, info };
|
|
316
256
|
}
|
|
317
|
-
function mapModel(params) {
|
|
318
|
-
if (params.provider === "hf-inference") {
|
|
319
|
-
return params.model;
|
|
320
|
-
}
|
|
321
|
-
if (!params.taskHint) {
|
|
322
|
-
throw new Error("taskHint must be specified when using a third-party provider");
|
|
323
|
-
}
|
|
324
|
-
const task = params.taskHint === "text-generation" && params.chatCompletion ? "conversational" : params.taskHint;
|
|
325
|
-
const model = (() => {
|
|
326
|
-
switch (params.provider) {
|
|
327
|
-
case "fal-ai":
|
|
328
|
-
return FAL_AI_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
329
|
-
case "replicate":
|
|
330
|
-
return REPLICATE_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
331
|
-
case "sambanova":
|
|
332
|
-
return SAMBANOVA_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
333
|
-
case "together":
|
|
334
|
-
return TOGETHER_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
335
|
-
}
|
|
336
|
-
})();
|
|
337
|
-
if (!model) {
|
|
338
|
-
throw new Error(`Model ${params.model} is not supported for task ${task} and provider ${params.provider}`);
|
|
339
|
-
}
|
|
340
|
-
return model;
|
|
341
|
-
}
|
|
342
257
|
function makeUrl(params) {
|
|
343
258
|
if (params.authMethod === "none" && params.provider !== "hf-inference") {
|
|
344
259
|
throw new Error("Authentication is required when requesting a third-party provider. Please provide accessToken");
|
|
@@ -722,7 +637,12 @@ async function buildPayload(args) {
|
|
|
722
637
|
|
|
723
638
|
// src/tasks/audio/textToSpeech.ts
|
|
724
639
|
async function textToSpeech(args, options) {
|
|
725
|
-
const
|
|
640
|
+
const payload = args.provider === "replicate" ? {
|
|
641
|
+
...omit(args, ["inputs", "parameters"]),
|
|
642
|
+
...args.parameters,
|
|
643
|
+
text: args.inputs
|
|
644
|
+
} : args;
|
|
645
|
+
const res = await request(payload, {
|
|
726
646
|
...options,
|
|
727
647
|
taskHint: "text-to-speech"
|
|
728
648
|
});
|
|
@@ -1352,14 +1272,10 @@ var HfInferenceEndpoint = class {
|
|
|
1352
1272
|
var INFERENCE_PROVIDERS = ["fal-ai", "replicate", "sambanova", "together", "hf-inference"];
|
|
1353
1273
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1354
1274
|
0 && (module.exports = {
|
|
1355
|
-
FAL_AI_SUPPORTED_MODEL_IDS,
|
|
1356
1275
|
HfInference,
|
|
1357
1276
|
HfInferenceEndpoint,
|
|
1358
1277
|
INFERENCE_PROVIDERS,
|
|
1359
1278
|
InferenceOutputError,
|
|
1360
|
-
REPLICATE_SUPPORTED_MODEL_IDS,
|
|
1361
|
-
SAMBANOVA_SUPPORTED_MODEL_IDS,
|
|
1362
|
-
TOGETHER_SUPPORTED_MODEL_IDS,
|
|
1363
1279
|
audioClassification,
|
|
1364
1280
|
audioToAudio,
|
|
1365
1281
|
automaticSpeechRecognition,
|
package/dist/index.js
CHANGED
|
@@ -43,126 +43,19 @@ __export(tasks_exports, {
|
|
|
43
43
|
|
|
44
44
|
// src/config.ts
|
|
45
45
|
var HF_HUB_URL = "https://huggingface.co";
|
|
46
|
+
var HF_ROUTER_URL = "https://router.huggingface.co";
|
|
46
47
|
|
|
47
48
|
// src/providers/fal-ai.ts
|
|
48
49
|
var FAL_AI_API_BASE_URL = "https://fal.run";
|
|
49
|
-
var FAL_AI_SUPPORTED_MODEL_IDS = {
|
|
50
|
-
"text-to-image": {
|
|
51
|
-
"black-forest-labs/FLUX.1-schnell": "fal-ai/flux/schnell",
|
|
52
|
-
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev",
|
|
53
|
-
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25",
|
|
54
|
-
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models",
|
|
55
|
-
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma",
|
|
56
|
-
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium",
|
|
57
|
-
"Warlord-K/Sana-1024": "fal-ai/sana",
|
|
58
|
-
"fal/AuraFlow-v0.2": "fal-ai/aura-flow",
|
|
59
|
-
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large",
|
|
60
|
-
"stabilityai/stable-diffusion-3.5-large-turbo": "fal-ai/stable-diffusion-v35-large/turbo",
|
|
61
|
-
"stabilityai/stable-diffusion-3.5-medium": "fal-ai/stable-diffusion-v35-medium",
|
|
62
|
-
"Kwai-Kolors/Kolors": "fal-ai/kolors"
|
|
63
|
-
},
|
|
64
|
-
"automatic-speech-recognition": {
|
|
65
|
-
"openai/whisper-large-v3": "fal-ai/whisper"
|
|
66
|
-
},
|
|
67
|
-
"text-to-video": {
|
|
68
|
-
"genmo/mochi-1-preview": "fal-ai/mochi-v1",
|
|
69
|
-
"tencent/HunyuanVideo": "fal-ai/hunyuan-video",
|
|
70
|
-
"THUDM/CogVideoX-5b": "fal-ai/cogvideox-5b",
|
|
71
|
-
"Lightricks/LTX-Video": "fal-ai/ltx-video"
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
50
|
|
|
75
51
|
// src/providers/replicate.ts
|
|
76
52
|
var REPLICATE_API_BASE_URL = "https://api.replicate.com";
|
|
77
|
-
var REPLICATE_SUPPORTED_MODEL_IDS = {
|
|
78
|
-
"text-to-image": {
|
|
79
|
-
"black-forest-labs/FLUX.1-dev": "black-forest-labs/flux-dev",
|
|
80
|
-
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/flux-schnell",
|
|
81
|
-
"ByteDance/Hyper-SD": "bytedance/hyper-flux-16step:382cf8959fb0f0d665b26e7e80b8d6dc3faaef1510f14ce017e8c732bb3d1eb7",
|
|
82
|
-
"ByteDance/SDXL-Lightning": "bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637",
|
|
83
|
-
"playgroundai/playground-v2.5-1024px-aesthetic": "playgroundai/playground-v2.5-1024px-aesthetic:a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24",
|
|
84
|
-
"stabilityai/stable-diffusion-3.5-large-turbo": "stability-ai/stable-diffusion-3.5-large-turbo",
|
|
85
|
-
"stabilityai/stable-diffusion-3.5-large": "stability-ai/stable-diffusion-3.5-large",
|
|
86
|
-
"stabilityai/stable-diffusion-3.5-medium": "stability-ai/stable-diffusion-3.5-medium",
|
|
87
|
-
"stabilityai/stable-diffusion-xl-base-1.0": "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc"
|
|
88
|
-
},
|
|
89
|
-
"text-to-speech": {
|
|
90
|
-
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:39a59319327b27327fa3095149c5a746e7f2aee18c75055c3368237a6503cd26"
|
|
91
|
-
},
|
|
92
|
-
"text-to-video": {
|
|
93
|
-
"genmo/mochi-1-preview": "genmoai/mochi-1:1944af04d098ef69bed7f9d335d102e652203f268ec4aaa2d836f6217217e460"
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
53
|
|
|
97
54
|
// src/providers/sambanova.ts
|
|
98
55
|
var SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
|
|
99
|
-
var SAMBANOVA_SUPPORTED_MODEL_IDS = {
|
|
100
|
-
/** Chat completion / conversational */
|
|
101
|
-
conversational: {
|
|
102
|
-
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
|
|
103
|
-
"Qwen/Qwen2.5-72B-Instruct": "Qwen2.5-72B-Instruct",
|
|
104
|
-
"Qwen/QwQ-32B-Preview": "QwQ-32B-Preview",
|
|
105
|
-
"meta-llama/Llama-3.3-70B-Instruct": "Meta-Llama-3.3-70B-Instruct",
|
|
106
|
-
"meta-llama/Llama-3.2-1B-Instruct": "Meta-Llama-3.2-1B-Instruct",
|
|
107
|
-
"meta-llama/Llama-3.2-3B-Instruct": "Meta-Llama-3.2-3B-Instruct",
|
|
108
|
-
"meta-llama/Llama-3.2-11B-Vision-Instruct": "Llama-3.2-11B-Vision-Instruct",
|
|
109
|
-
"meta-llama/Llama-3.2-90B-Vision-Instruct": "Llama-3.2-90B-Vision-Instruct",
|
|
110
|
-
"meta-llama/Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
|
|
111
|
-
"meta-llama/Llama-3.1-70B-Instruct": "Meta-Llama-3.1-70B-Instruct",
|
|
112
|
-
"meta-llama/Llama-3.1-405B-Instruct": "Meta-Llama-3.1-405B-Instruct",
|
|
113
|
-
"meta-llama/Llama-Guard-3-8B": "Meta-Llama-Guard-3-8B"
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
56
|
|
|
117
57
|
// src/providers/together.ts
|
|
118
58
|
var TOGETHER_API_BASE_URL = "https://api.together.xyz";
|
|
119
|
-
var TOGETHER_SUPPORTED_MODEL_IDS = {
|
|
120
|
-
"text-to-image": {
|
|
121
|
-
"black-forest-labs/FLUX.1-Canny-dev": "black-forest-labs/FLUX.1-canny",
|
|
122
|
-
"black-forest-labs/FLUX.1-Depth-dev": "black-forest-labs/FLUX.1-depth",
|
|
123
|
-
"black-forest-labs/FLUX.1-dev": "black-forest-labs/FLUX.1-dev",
|
|
124
|
-
"black-forest-labs/FLUX.1-Redux-dev": "black-forest-labs/FLUX.1-redux",
|
|
125
|
-
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/FLUX.1-pro",
|
|
126
|
-
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0"
|
|
127
|
-
},
|
|
128
|
-
conversational: {
|
|
129
|
-
"databricks/dbrx-instruct": "databricks/dbrx-instruct",
|
|
130
|
-
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1",
|
|
131
|
-
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3",
|
|
132
|
-
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat",
|
|
133
|
-
"google/gemma-2-9b-it": "google/gemma-2-9b-it",
|
|
134
|
-
"google/gemma-2b-it": "google/gemma-2-27b-it",
|
|
135
|
-
"meta-llama/Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
|
|
136
|
-
"meta-llama/Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
|
|
137
|
-
"meta-llama/Llama-3.2-11B-Vision-Instruct": "meta-llama/Llama-Vision-Free",
|
|
138
|
-
"meta-llama/Llama-3.2-3B-Instruct": "meta-llama/Llama-3.2-3B-Instruct-Turbo",
|
|
139
|
-
"meta-llama/Llama-3.2-90B-Vision-Instruct": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
|
|
140
|
-
"meta-llama/Llama-3.3-70B-Instruct": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
141
|
-
"meta-llama/Meta-Llama-3-70B-Instruct": "meta-llama/Llama-3-70b-chat-hf",
|
|
142
|
-
"meta-llama/Meta-Llama-3-8B-Instruct": "meta-llama/Meta-Llama-3-8B-Instruct-Turbo",
|
|
143
|
-
"meta-llama/Meta-Llama-3.1-405B-Instruct": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
|
|
144
|
-
"meta-llama/Meta-Llama-3.1-70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
|
|
145
|
-
"meta-llama/Meta-Llama-3.1-8B-Instruct": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo-128K",
|
|
146
|
-
"microsoft/WizardLM-2-8x22B": "microsoft/WizardLM-2-8x22B",
|
|
147
|
-
"mistralai/Mistral-7B-Instruct-v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
|
|
148
|
-
"mistralai/Mistral-Small-24B-Instruct-2501": "mistralai/Mistral-Small-24B-Instruct-2501",
|
|
149
|
-
"mistralai/Mixtral-8x22B-Instruct-v0.1": "mistralai/Mixtral-8x22B-Instruct-v0.1",
|
|
150
|
-
"mistralai/Mixtral-8x7B-Instruct-v0.1": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
151
|
-
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
|
152
|
-
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
|
|
153
|
-
"Qwen/Qwen2-72B-Instruct": "Qwen/Qwen2-72B-Instruct",
|
|
154
|
-
"Qwen/Qwen2.5-72B-Instruct": "Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
155
|
-
"Qwen/Qwen2.5-7B-Instruct": "Qwen/Qwen2.5-7B-Instruct-Turbo",
|
|
156
|
-
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
157
|
-
"Qwen/QwQ-32B-Preview": "Qwen/QwQ-32B-Preview",
|
|
158
|
-
"scb10x/llama-3-typhoon-v1.5-8b-instruct": "scb10x/scb10x-llama3-typhoon-v1-5-8b-instruct",
|
|
159
|
-
"scb10x/llama-3-typhoon-v1.5x-70b-instruct-awq": "scb10x/scb10x-llama3-typhoon-v1-5x-4f316"
|
|
160
|
-
},
|
|
161
|
-
"text-generation": {
|
|
162
|
-
"meta-llama/Llama-2-70b-hf": "meta-llama/Llama-2-70b-hf",
|
|
163
|
-
"mistralai/Mixtral-8x7B-v0.1": "mistralai/Mixtral-8x7B-v0.1"
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
59
|
|
|
167
60
|
// src/lib/isUrl.ts
|
|
168
61
|
function isUrl(modelOrUrl) {
|
|
@@ -171,10 +64,62 @@ function isUrl(modelOrUrl) {
|
|
|
171
64
|
|
|
172
65
|
// package.json
|
|
173
66
|
var name = "@huggingface/inference";
|
|
174
|
-
var version = "3.
|
|
67
|
+
var version = "3.2.0";
|
|
68
|
+
|
|
69
|
+
// src/providers/consts.ts
|
|
70
|
+
var HARDCODED_MODEL_ID_MAPPING = {
|
|
71
|
+
/**
|
|
72
|
+
* "HF model ID" => "Model ID on Inference Provider's side"
|
|
73
|
+
*/
|
|
74
|
+
// "Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/lib/getProviderModelId.ts
|
|
78
|
+
var inferenceProviderMappingCache = /* @__PURE__ */ new Map();
|
|
79
|
+
async function getProviderModelId(params, args, options = {}) {
|
|
80
|
+
if (params.provider === "hf-inference") {
|
|
81
|
+
return params.model;
|
|
82
|
+
}
|
|
83
|
+
if (!options.taskHint) {
|
|
84
|
+
throw new Error("taskHint must be specified when using a third-party provider");
|
|
85
|
+
}
|
|
86
|
+
const task = options.taskHint === "text-generation" && options.chatCompletion ? "conversational" : options.taskHint;
|
|
87
|
+
if (HARDCODED_MODEL_ID_MAPPING[params.model]) {
|
|
88
|
+
return HARDCODED_MODEL_ID_MAPPING[params.model];
|
|
89
|
+
}
|
|
90
|
+
let inferenceProviderMapping;
|
|
91
|
+
if (inferenceProviderMappingCache.has(params.model)) {
|
|
92
|
+
inferenceProviderMapping = inferenceProviderMappingCache.get(params.model);
|
|
93
|
+
} else {
|
|
94
|
+
inferenceProviderMapping = await (options?.fetch ?? fetch)(
|
|
95
|
+
`${HF_HUB_URL}/api/models/${params.model}?expand[]=inferenceProviderMapping`,
|
|
96
|
+
{
|
|
97
|
+
headers: args.accessToken?.startsWith("hf_") ? { Authorization: `Bearer ${args.accessToken}` } : {}
|
|
98
|
+
}
|
|
99
|
+
).then((resp) => resp.json()).then((json) => json.inferenceProviderMapping).catch(() => null);
|
|
100
|
+
}
|
|
101
|
+
if (!inferenceProviderMapping) {
|
|
102
|
+
throw new Error(`We have not been able to find inference provider information for model ${params.model}.`);
|
|
103
|
+
}
|
|
104
|
+
const providerMapping = inferenceProviderMapping[params.provider];
|
|
105
|
+
if (providerMapping) {
|
|
106
|
+
if (providerMapping.task !== task) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Model ${params.model} is not supported for task ${task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (providerMapping.status === "staging") {
|
|
112
|
+
console.warn(
|
|
113
|
+
`Model ${params.model} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return providerMapping.providerId;
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`Model ${params.model} is not supported provider ${params.provider}.`);
|
|
119
|
+
}
|
|
175
120
|
|
|
176
121
|
// src/lib/makeRequestOptions.ts
|
|
177
|
-
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${
|
|
122
|
+
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;
|
|
178
123
|
var tasks = null;
|
|
179
124
|
async function makeRequestOptions(args, options) {
|
|
180
125
|
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args;
|
|
@@ -190,16 +135,15 @@ async function makeRequestOptions(args, options) {
|
|
|
190
135
|
if (maybeModel && isUrl(maybeModel)) {
|
|
191
136
|
throw new Error(`Model URLs are no longer supported. Use endpointUrl instead.`);
|
|
192
137
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (taskHint) {
|
|
196
|
-
model = mapModel({ model: await loadDefaultModel(taskHint), provider, taskHint, chatCompletion: chatCompletion2 });
|
|
197
|
-
} else {
|
|
198
|
-
throw new Error("No model provided, and no default model found for this task");
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
model = mapModel({ model: maybeModel, provider, taskHint, chatCompletion: chatCompletion2 });
|
|
138
|
+
if (!maybeModel && !taskHint) {
|
|
139
|
+
throw new Error("No model provided, and no task has been specified.");
|
|
202
140
|
}
|
|
141
|
+
const hfModel = maybeModel ?? await loadDefaultModel(taskHint);
|
|
142
|
+
const model = await getProviderModelId({ model: hfModel, provider }, args, {
|
|
143
|
+
taskHint,
|
|
144
|
+
chatCompletion: chatCompletion2,
|
|
145
|
+
fetch: options?.fetch
|
|
146
|
+
});
|
|
203
147
|
const authMethod = accessToken ? accessToken.startsWith("hf_") ? "hf-token" : "provider-key" : includeCredentials === "include" ? "credentials-include" : "none";
|
|
204
148
|
const url = endpointUrl ? chatCompletion2 ? endpointUrl + `/v1/chat/completions` : endpointUrl : makeUrl({
|
|
205
149
|
authMethod,
|
|
@@ -255,31 +199,6 @@ async function makeRequestOptions(args, options) {
|
|
|
255
199
|
};
|
|
256
200
|
return { url, info };
|
|
257
201
|
}
|
|
258
|
-
function mapModel(params) {
|
|
259
|
-
if (params.provider === "hf-inference") {
|
|
260
|
-
return params.model;
|
|
261
|
-
}
|
|
262
|
-
if (!params.taskHint) {
|
|
263
|
-
throw new Error("taskHint must be specified when using a third-party provider");
|
|
264
|
-
}
|
|
265
|
-
const task = params.taskHint === "text-generation" && params.chatCompletion ? "conversational" : params.taskHint;
|
|
266
|
-
const model = (() => {
|
|
267
|
-
switch (params.provider) {
|
|
268
|
-
case "fal-ai":
|
|
269
|
-
return FAL_AI_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
270
|
-
case "replicate":
|
|
271
|
-
return REPLICATE_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
272
|
-
case "sambanova":
|
|
273
|
-
return SAMBANOVA_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
274
|
-
case "together":
|
|
275
|
-
return TOGETHER_SUPPORTED_MODEL_IDS[task]?.[params.model];
|
|
276
|
-
}
|
|
277
|
-
})();
|
|
278
|
-
if (!model) {
|
|
279
|
-
throw new Error(`Model ${params.model} is not supported for task ${task} and provider ${params.provider}`);
|
|
280
|
-
}
|
|
281
|
-
return model;
|
|
282
|
-
}
|
|
283
202
|
function makeUrl(params) {
|
|
284
203
|
if (params.authMethod === "none" && params.provider !== "hf-inference") {
|
|
285
204
|
throw new Error("Authentication is required when requesting a third-party provider. Please provide accessToken");
|
|
@@ -663,7 +582,12 @@ async function buildPayload(args) {
|
|
|
663
582
|
|
|
664
583
|
// src/tasks/audio/textToSpeech.ts
|
|
665
584
|
async function textToSpeech(args, options) {
|
|
666
|
-
const
|
|
585
|
+
const payload = args.provider === "replicate" ? {
|
|
586
|
+
...omit(args, ["inputs", "parameters"]),
|
|
587
|
+
...args.parameters,
|
|
588
|
+
text: args.inputs
|
|
589
|
+
} : args;
|
|
590
|
+
const res = await request(payload, {
|
|
667
591
|
...options,
|
|
668
592
|
taskHint: "text-to-speech"
|
|
669
593
|
});
|
|
@@ -1292,14 +1216,10 @@ var HfInferenceEndpoint = class {
|
|
|
1292
1216
|
// src/types.ts
|
|
1293
1217
|
var INFERENCE_PROVIDERS = ["fal-ai", "replicate", "sambanova", "together", "hf-inference"];
|
|
1294
1218
|
export {
|
|
1295
|
-
FAL_AI_SUPPORTED_MODEL_IDS,
|
|
1296
1219
|
HfInference,
|
|
1297
1220
|
HfInferenceEndpoint,
|
|
1298
1221
|
INFERENCE_PROVIDERS,
|
|
1299
1222
|
InferenceOutputError,
|
|
1300
|
-
REPLICATE_SUPPORTED_MODEL_IDS,
|
|
1301
|
-
SAMBANOVA_SUPPORTED_MODEL_IDS,
|
|
1302
|
-
TOGETHER_SUPPORTED_MODEL_IDS,
|
|
1303
1223
|
audioClassification,
|
|
1304
1224
|
audioToAudio,
|
|
1305
1225
|
automaticSpeechRecognition,
|
package/dist/src/config.d.ts
CHANGED
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,2BAA2B,CAAC;AACnD,eAAO,MAAM,aAAa,kCAAkC,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
export type { ProviderMapping } from "./providers/types";
|
|
2
1
|
export { HfInference, HfInferenceEndpoint } from "./HfInference";
|
|
3
2
|
export { InferenceOutputError } from "./lib/InferenceOutputError";
|
|
4
|
-
export { FAL_AI_SUPPORTED_MODEL_IDS } from "./providers/fal-ai";
|
|
5
|
-
export { REPLICATE_SUPPORTED_MODEL_IDS } from "./providers/replicate";
|
|
6
|
-
export { SAMBANOVA_SUPPORTED_MODEL_IDS } from "./providers/sambanova";
|
|
7
|
-
export { TOGETHER_SUPPORTED_MODEL_IDS } from "./providers/together";
|
|
8
3
|
export * from "./types";
|
|
9
4
|
export * from "./tasks";
|
|
10
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InferenceProvider, InferenceTask, Options, RequestArgs } from "../types";
|
|
2
|
+
export declare function getProviderModelId(params: {
|
|
3
|
+
model: string;
|
|
4
|
+
provider: InferenceProvider;
|
|
5
|
+
}, args: RequestArgs, options?: {
|
|
6
|
+
taskHint?: InferenceTask;
|
|
7
|
+
chatCompletion?: boolean;
|
|
8
|
+
fetch?: Options["fetch"];
|
|
9
|
+
}): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=getProviderModelId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getProviderModelId.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderModelId.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAW,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAShG,wBAAsB,kBAAkB,CACvC,MAAM,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,iBAAiB,CAAC;CAC5B,EACD,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE;IACR,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpB,GACJ,OAAO,CAAC,MAAM,CAAC,CAoDjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeRequestOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/makeRequestOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"makeRequestOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/makeRequestOptions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAapE;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,WAAW,GAAG;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,EACD,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;IACnC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAqH7C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelId } from "../types";
|
|
2
|
+
type ProviderId = string;
|
|
3
|
+
/**
|
|
4
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co
|
|
5
|
+
* for a given Inference Provider,
|
|
6
|
+
* you can add it to the following dictionary, for dev purposes.
|
|
7
|
+
*/
|
|
8
|
+
export declare const HARDCODED_MODEL_ID_MAPPING: Record<ModelId, ProviderId>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=consts.d.ts.map
|