@huggingface/inference 3.14.0 → 4.0.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 +104 -1
- package/dist/commonjs/errors.d.ts +46 -0
- package/dist/commonjs/errors.d.ts.map +1 -0
- package/dist/commonjs/errors.js +70 -0
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +2 -3
- package/dist/commonjs/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/commonjs/lib/getInferenceProviderMapping.js +27 -16
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +5 -3
- package/dist/commonjs/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/commonjs/lib/makeRequestOptions.js +12 -11
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.d.ts.map +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/commonjs/providers/black-forest-labs.js +4 -4
- package/dist/commonjs/providers/fal-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/fal-ai.js +29 -17
- package/dist/commonjs/providers/featherless-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/featherless-ai.js +10 -4
- package/dist/commonjs/providers/hf-inference.d.ts.map +1 -1
- package/dist/commonjs/providers/hf-inference.js +27 -30
- package/dist/commonjs/providers/hyperbolic.d.ts.map +1 -1
- package/dist/commonjs/providers/hyperbolic.js +3 -3
- package/dist/commonjs/providers/nebius.d.ts.map +1 -1
- package/dist/commonjs/providers/nebius.js +2 -2
- package/dist/commonjs/providers/novita.d.ts +5 -6
- package/dist/commonjs/providers/novita.d.ts.map +1 -1
- package/dist/commonjs/providers/novita.js +66 -16
- package/dist/commonjs/providers/nscale.d.ts.map +1 -1
- package/dist/commonjs/providers/nscale.js +2 -2
- package/dist/commonjs/providers/ovhcloud.d.ts.map +1 -1
- package/dist/commonjs/providers/ovhcloud.js +2 -2
- package/dist/commonjs/providers/providerHelper.js +3 -3
- package/dist/commonjs/providers/replicate.js +4 -4
- package/dist/commonjs/providers/sambanova.d.ts +16 -0
- package/dist/commonjs/providers/sambanova.d.ts.map +1 -1
- package/dist/commonjs/providers/sambanova.js +2 -18
- package/dist/commonjs/providers/together.d.ts.map +1 -1
- package/dist/commonjs/providers/together.js +3 -3
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.js +2 -2
- package/dist/commonjs/utils/request.d.ts.map +1 -1
- package/dist/commonjs/utils/request.js +77 -12
- package/dist/commonjs/vendor/type-fest/basic.d.ts +33 -0
- package/dist/commonjs/vendor/type-fest/basic.d.ts.map +1 -0
- package/dist/commonjs/vendor/type-fest/basic.js +2 -0
- package/dist/esm/errors.d.ts +46 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +62 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/esm/lib/getInferenceProviderMapping.js +27 -16
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +5 -3
- package/dist/esm/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/esm/lib/makeRequestOptions.js +12 -11
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.d.ts.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/esm/providers/black-forest-labs.js +4 -4
- package/dist/esm/providers/fal-ai.d.ts.map +1 -1
- package/dist/esm/providers/fal-ai.js +29 -17
- package/dist/esm/providers/featherless-ai.d.ts.map +1 -1
- package/dist/esm/providers/featherless-ai.js +10 -4
- package/dist/esm/providers/hf-inference.d.ts.map +1 -1
- package/dist/esm/providers/hf-inference.js +27 -30
- package/dist/esm/providers/hyperbolic.d.ts.map +1 -1
- package/dist/esm/providers/hyperbolic.js +3 -3
- package/dist/esm/providers/nebius.d.ts.map +1 -1
- package/dist/esm/providers/nebius.js +2 -2
- package/dist/esm/providers/novita.d.ts +5 -6
- package/dist/esm/providers/novita.d.ts.map +1 -1
- package/dist/esm/providers/novita.js +66 -16
- package/dist/esm/providers/nscale.d.ts.map +1 -1
- package/dist/esm/providers/nscale.js +2 -2
- package/dist/esm/providers/ovhcloud.d.ts.map +1 -1
- package/dist/esm/providers/ovhcloud.js +2 -2
- package/dist/esm/providers/providerHelper.js +3 -3
- package/dist/esm/providers/replicate.js +4 -4
- package/dist/esm/providers/sambanova.d.ts +16 -0
- package/dist/esm/providers/sambanova.d.ts.map +1 -1
- package/dist/esm/providers/sambanova.js +2 -18
- package/dist/esm/providers/together.d.ts.map +1 -1
- package/dist/esm/providers/together.js +3 -3
- package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/esm/tasks/audio/automaticSpeechRecognition.js +2 -2
- package/dist/esm/utils/request.d.ts.map +1 -1
- package/dist/esm/utils/request.js +77 -12
- package/dist/esm/vendor/type-fest/basic.d.ts +33 -0
- package/dist/esm/vendor/type-fest/basic.d.ts.map +1 -0
- package/dist/esm/vendor/type-fest/basic.js +1 -0
- package/package.json +2 -2
- package/src/errors.ts +82 -0
- package/src/index.ts +1 -1
- package/src/lib/getInferenceProviderMapping.ts +42 -22
- package/src/lib/getProviderHelper.ts +9 -3
- package/src/lib/makeRequestOptions.ts +20 -11
- package/src/package.ts +1 -1
- package/src/providers/black-forest-labs.ts +14 -4
- package/src/providers/fal-ai.ts +59 -23
- package/src/providers/featherless-ai.ts +10 -4
- package/src/providers/hf-inference.ts +75 -34
- package/src/providers/hyperbolic.ts +3 -4
- package/src/providers/nebius.ts +2 -2
- package/src/providers/novita.ts +103 -23
- package/src/providers/nscale.ts +2 -2
- package/src/providers/ovhcloud.ts +2 -2
- package/src/providers/providerHelper.ts +3 -3
- package/src/providers/replicate.ts +4 -4
- package/src/providers/sambanova.ts +3 -4
- package/src/providers/together.ts +3 -3
- package/src/tasks/audio/automaticSpeechRecognition.ts +2 -2
- package/src/tasks/cv/textToVideo.ts +2 -2
- package/src/utils/request.ts +127 -14
- package/src/vendor/type-fest/basic.ts +31 -0
- package/src/vendor/type-fest/license-cc0 +121 -0
- package/src/vendor/type-fest/license-mit +9 -0
- package/dist/commonjs/lib/InferenceOutputError.d.ts +0 -4
- package/dist/commonjs/lib/InferenceOutputError.d.ts.map +0 -1
- package/dist/commonjs/lib/InferenceOutputError.js +0 -10
- package/dist/esm/lib/InferenceOutputError.d.ts +0 -4
- package/dist/esm/lib/InferenceOutputError.d.ts.map +0 -1
- package/dist/esm/lib/InferenceOutputError.js +0 -6
- package/src/lib/InferenceOutputError.ts +0 -8
package/src/providers/fal-ai.ts
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
import { base64FromBytes } from "../utils/base64FromBytes.js";
|
|
18
18
|
|
|
19
19
|
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
20
|
-
import { InferenceOutputError } from "../lib/InferenceOutputError.js";
|
|
21
20
|
import { isUrl } from "../lib/isUrl.js";
|
|
22
21
|
import type { BodyParams, HeaderParams, ModelId, RequestArgs, UrlParams } from "../types.js";
|
|
23
22
|
import { delay } from "../utils/delay.js";
|
|
@@ -30,6 +29,11 @@ import {
|
|
|
30
29
|
} from "./providerHelper.js";
|
|
31
30
|
import { HF_HUB_URL } from "../config.js";
|
|
32
31
|
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition.js";
|
|
32
|
+
import {
|
|
33
|
+
InferenceClientInputError,
|
|
34
|
+
InferenceClientProviderApiError,
|
|
35
|
+
InferenceClientProviderOutputError,
|
|
36
|
+
} from "../errors.js";
|
|
33
37
|
|
|
34
38
|
export interface FalAiQueueOutput {
|
|
35
39
|
request_id: string;
|
|
@@ -122,7 +126,7 @@ export class FalAITextToImageTask extends FalAITask implements TextToImageTaskHe
|
|
|
122
126
|
return await urlResponse.blob();
|
|
123
127
|
}
|
|
124
128
|
|
|
125
|
-
throw new
|
|
129
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Fal.ai text-to-image API");
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
|
|
@@ -150,11 +154,13 @@ export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHe
|
|
|
150
154
|
headers?: Record<string, string>
|
|
151
155
|
): Promise<Blob> {
|
|
152
156
|
if (!url || !headers) {
|
|
153
|
-
throw new
|
|
157
|
+
throw new InferenceClientInputError("URL and headers are required for text-to-video task");
|
|
154
158
|
}
|
|
155
159
|
const requestId = response.request_id;
|
|
156
160
|
if (!requestId) {
|
|
157
|
-
throw new
|
|
161
|
+
throw new InferenceClientProviderOutputError(
|
|
162
|
+
"Received malformed response from Fal.ai text-to-video API: no request ID found in the response"
|
|
163
|
+
);
|
|
158
164
|
}
|
|
159
165
|
let status = response.status;
|
|
160
166
|
|
|
@@ -176,12 +182,22 @@ export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHe
|
|
|
176
182
|
const statusResponse = await fetch(statusUrl, { headers });
|
|
177
183
|
|
|
178
184
|
if (!statusResponse.ok) {
|
|
179
|
-
throw new
|
|
185
|
+
throw new InferenceClientProviderApiError(
|
|
186
|
+
"Failed to fetch response status from fal-ai API",
|
|
187
|
+
{ url: statusUrl, method: "GET" },
|
|
188
|
+
{
|
|
189
|
+
requestId: statusResponse.headers.get("x-request-id") ?? "",
|
|
190
|
+
status: statusResponse.status,
|
|
191
|
+
body: await statusResponse.text(),
|
|
192
|
+
}
|
|
193
|
+
);
|
|
180
194
|
}
|
|
181
195
|
try {
|
|
182
196
|
status = (await statusResponse.json()).status;
|
|
183
197
|
} catch (error) {
|
|
184
|
-
throw new
|
|
198
|
+
throw new InferenceClientProviderOutputError(
|
|
199
|
+
"Failed to parse status response from fal-ai API: received malformed response"
|
|
200
|
+
);
|
|
185
201
|
}
|
|
186
202
|
}
|
|
187
203
|
|
|
@@ -190,7 +206,9 @@ export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHe
|
|
|
190
206
|
try {
|
|
191
207
|
result = await resultResponse.json();
|
|
192
208
|
} catch (error) {
|
|
193
|
-
throw new
|
|
209
|
+
throw new InferenceClientProviderOutputError(
|
|
210
|
+
"Failed to parse result response from fal-ai API: received malformed response"
|
|
211
|
+
);
|
|
194
212
|
}
|
|
195
213
|
if (
|
|
196
214
|
typeof result === "object" &&
|
|
@@ -205,8 +223,10 @@ export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHe
|
|
|
205
223
|
const urlResponse = await fetch(result.video.url);
|
|
206
224
|
return await urlResponse.blob();
|
|
207
225
|
} else {
|
|
208
|
-
throw new
|
|
209
|
-
|
|
226
|
+
throw new InferenceClientProviderOutputError(
|
|
227
|
+
`Received malformed response from Fal.ai text-to-video API: expected { video: { url: string } } result format, got instead: ${JSON.stringify(
|
|
228
|
+
result
|
|
229
|
+
)}`
|
|
210
230
|
);
|
|
211
231
|
}
|
|
212
232
|
}
|
|
@@ -221,8 +241,10 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au
|
|
|
221
241
|
override async getResponse(response: unknown): Promise<AutomaticSpeechRecognitionOutput> {
|
|
222
242
|
const res = response as FalAIAutomaticSpeechRecognitionOutput;
|
|
223
243
|
if (typeof res?.text !== "string") {
|
|
224
|
-
throw new
|
|
225
|
-
`
|
|
244
|
+
throw new InferenceClientProviderOutputError(
|
|
245
|
+
`Received malformed response from Fal.ai Automatic Speech Recognition API: expected { text: string } format, got instead: ${JSON.stringify(
|
|
246
|
+
response
|
|
247
|
+
)}`
|
|
226
248
|
);
|
|
227
249
|
}
|
|
228
250
|
return { text: res.text };
|
|
@@ -232,12 +254,12 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au
|
|
|
232
254
|
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
233
255
|
const contentType = blob?.type;
|
|
234
256
|
if (!contentType) {
|
|
235
|
-
throw new
|
|
257
|
+
throw new InferenceClientInputError(
|
|
236
258
|
`Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai.`
|
|
237
259
|
);
|
|
238
260
|
}
|
|
239
261
|
if (!FAL_AI_SUPPORTED_BLOB_TYPES.includes(contentType)) {
|
|
240
|
-
throw new
|
|
262
|
+
throw new InferenceClientInputError(
|
|
241
263
|
`Provider fal-ai does not support blob type ${contentType} - supported content types are: ${FAL_AI_SUPPORTED_BLOB_TYPES.join(
|
|
242
264
|
", "
|
|
243
265
|
)}`
|
|
@@ -263,21 +285,35 @@ export class FalAITextToSpeechTask extends FalAITask {
|
|
|
263
285
|
override async getResponse(response: unknown): Promise<Blob> {
|
|
264
286
|
const res = response as FalAITextToSpeechOutput;
|
|
265
287
|
if (typeof res?.audio?.url !== "string") {
|
|
266
|
-
throw new
|
|
267
|
-
`
|
|
288
|
+
throw new InferenceClientProviderOutputError(
|
|
289
|
+
`Received malformed response from Fal.ai Text-to-Speech API: expected { audio: { url: string } } format, got instead: ${JSON.stringify(
|
|
290
|
+
response
|
|
291
|
+
)}`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
const urlResponse = await fetch(res.audio.url);
|
|
295
|
+
if (!urlResponse.ok) {
|
|
296
|
+
throw new InferenceClientProviderApiError(
|
|
297
|
+
`Failed to fetch audio from ${res.audio.url}: ${urlResponse.statusText}`,
|
|
298
|
+
{ url: res.audio.url, method: "GET", headers: { "Content-Type": "application/json" } },
|
|
299
|
+
{
|
|
300
|
+
requestId: urlResponse.headers.get("x-request-id") ?? "",
|
|
301
|
+
status: urlResponse.status,
|
|
302
|
+
body: await urlResponse.text(),
|
|
303
|
+
}
|
|
268
304
|
);
|
|
269
305
|
}
|
|
270
306
|
try {
|
|
271
|
-
const urlResponse = await fetch(res.audio.url);
|
|
272
|
-
if (!urlResponse.ok) {
|
|
273
|
-
throw new Error(`Failed to fetch audio from ${res.audio.url}: ${urlResponse.statusText}`);
|
|
274
|
-
}
|
|
275
307
|
return await urlResponse.blob();
|
|
276
308
|
} catch (error) {
|
|
277
|
-
throw new
|
|
278
|
-
`
|
|
279
|
-
|
|
280
|
-
|
|
309
|
+
throw new InferenceClientProviderApiError(
|
|
310
|
+
`Failed to fetch audio from ${res.audio.url}: ${error instanceof Error ? error.message : String(error)}`,
|
|
311
|
+
{ url: res.audio.url, method: "GET", headers: { "Content-Type": "application/json" } },
|
|
312
|
+
{
|
|
313
|
+
requestId: urlResponse.headers.get("x-request-id") ?? "",
|
|
314
|
+
status: urlResponse.status,
|
|
315
|
+
body: await urlResponse.text(),
|
|
316
|
+
}
|
|
281
317
|
);
|
|
282
318
|
}
|
|
283
319
|
}
|
|
@@ -4,9 +4,10 @@ import type {
|
|
|
4
4
|
TextGenerationOutput,
|
|
5
5
|
TextGenerationOutputFinishReason,
|
|
6
6
|
} from "@huggingface/tasks";
|
|
7
|
-
import { InferenceOutputError } from "../lib/InferenceOutputError.js";
|
|
8
7
|
import type { BodyParams } from "../types.js";
|
|
9
8
|
import { BaseConversationalTask, BaseTextGenerationTask } from "./providerHelper.js";
|
|
9
|
+
import { omit } from "../utils/omit.js";
|
|
10
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
10
11
|
|
|
11
12
|
interface FeatherlessAITextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
|
|
12
13
|
choices: Array<{
|
|
@@ -33,9 +34,14 @@ export class FeatherlessAITextGenerationTask extends BaseTextGenerationTask {
|
|
|
33
34
|
|
|
34
35
|
override preparePayload(params: BodyParams<TextGenerationInput>): Record<string, unknown> {
|
|
35
36
|
return {
|
|
36
|
-
...params.args,
|
|
37
|
-
...params.args.parameters,
|
|
38
37
|
model: params.model,
|
|
38
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
39
|
+
...(params.args.parameters
|
|
40
|
+
? {
|
|
41
|
+
max_tokens: params.args.parameters.max_new_tokens,
|
|
42
|
+
...omit(params.args.parameters, "max_new_tokens"),
|
|
43
|
+
}
|
|
44
|
+
: undefined),
|
|
39
45
|
prompt: params.args.inputs,
|
|
40
46
|
};
|
|
41
47
|
}
|
|
@@ -52,6 +58,6 @@ export class FeatherlessAITextGenerationTask extends BaseTextGenerationTask {
|
|
|
52
58
|
generated_text: completion.text,
|
|
53
59
|
};
|
|
54
60
|
}
|
|
55
|
-
throw new
|
|
61
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Featherless AI text generation API");
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -34,7 +34,7 @@ import type {
|
|
|
34
34
|
ZeroShotImageClassificationOutput,
|
|
35
35
|
} from "@huggingface/tasks";
|
|
36
36
|
import { HF_ROUTER_URL } from "../config.js";
|
|
37
|
-
import {
|
|
37
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
38
38
|
import type { TabularClassificationOutput } from "../tasks/tabular/tabularClassification.js";
|
|
39
39
|
import type { BodyParams, RequestArgs, UrlParams } from "../types.js";
|
|
40
40
|
import { toArray } from "../utils/toArray.js";
|
|
@@ -127,7 +127,9 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT
|
|
|
127
127
|
outputType?: "url" | "blob"
|
|
128
128
|
): Promise<string | Blob> {
|
|
129
129
|
if (!response) {
|
|
130
|
-
throw new
|
|
130
|
+
throw new InferenceClientProviderOutputError(
|
|
131
|
+
"Received malformed response from HF-Inference text-to-image API: response is undefined"
|
|
132
|
+
);
|
|
131
133
|
}
|
|
132
134
|
if (typeof response == "object") {
|
|
133
135
|
if ("data" in response && Array.isArray(response.data) && response.data[0].b64_json) {
|
|
@@ -154,7 +156,9 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT
|
|
|
154
156
|
}
|
|
155
157
|
return response;
|
|
156
158
|
}
|
|
157
|
-
throw new
|
|
159
|
+
throw new InferenceClientProviderOutputError(
|
|
160
|
+
"Received malformed response from HF-Inference text-to-image API: expected a Blob"
|
|
161
|
+
);
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
|
|
@@ -195,13 +199,14 @@ export class HFInferenceTextGenerationTask extends HFInferenceTask implements Te
|
|
|
195
199
|
if (Array.isArray(res) && res.every((x) => "generated_text" in x && typeof x?.generated_text === "string")) {
|
|
196
200
|
return (res as TextGenerationOutput[])?.[0];
|
|
197
201
|
}
|
|
198
|
-
throw new
|
|
202
|
+
throw new InferenceClientProviderOutputError(
|
|
203
|
+
"Received malformed response from HF-Inference text generation API: expected Array<{generated_text: string}>"
|
|
204
|
+
);
|
|
199
205
|
}
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
export class HFInferenceAudioClassificationTask extends HFInferenceTask implements AudioClassificationTaskHelper {
|
|
203
209
|
override async getResponse(response: unknown): Promise<AudioClassificationOutput> {
|
|
204
|
-
// Add type checking/validation for the 'unknown' input
|
|
205
210
|
if (
|
|
206
211
|
Array.isArray(response) &&
|
|
207
212
|
response.every(
|
|
@@ -209,11 +214,11 @@ export class HFInferenceAudioClassificationTask extends HFInferenceTask implemen
|
|
|
209
214
|
typeof x === "object" && x !== null && typeof x.label === "string" && typeof x.score === "number"
|
|
210
215
|
)
|
|
211
216
|
) {
|
|
212
|
-
// If validation passes, it's safe to return as AudioClassificationOutput
|
|
213
217
|
return response;
|
|
214
218
|
}
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
throw new InferenceClientProviderOutputError(
|
|
220
|
+
"Received malformed response from HF-Inference audio-classification API: expected Array<{label: string, score: number}> but received different format"
|
|
221
|
+
);
|
|
217
222
|
}
|
|
218
223
|
}
|
|
219
224
|
|
|
@@ -238,7 +243,9 @@ export class HFInferenceAutomaticSpeechRecognitionTask
|
|
|
238
243
|
export class HFInferenceAudioToAudioTask extends HFInferenceTask implements AudioToAudioTaskHelper {
|
|
239
244
|
override async getResponse(response: AudioToAudioOutput[]): Promise<AudioToAudioOutput[]> {
|
|
240
245
|
if (!Array.isArray(response)) {
|
|
241
|
-
throw new
|
|
246
|
+
throw new InferenceClientProviderOutputError(
|
|
247
|
+
"Received malformed response from HF-Inference audio-to-audio API: expected Array"
|
|
248
|
+
);
|
|
242
249
|
}
|
|
243
250
|
if (
|
|
244
251
|
!response.every((elem): elem is AudioToAudioOutput => {
|
|
@@ -254,7 +261,9 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi
|
|
|
254
261
|
);
|
|
255
262
|
})
|
|
256
263
|
) {
|
|
257
|
-
throw new
|
|
264
|
+
throw new InferenceClientProviderOutputError(
|
|
265
|
+
"Received malformed response from HF-Inference audio-to-audio API: expected Array<{label: string, audio: Blob}>"
|
|
266
|
+
);
|
|
258
267
|
}
|
|
259
268
|
return response;
|
|
260
269
|
}
|
|
@@ -281,7 +290,9 @@ export class HFInferenceDocumentQuestionAnsweringTask
|
|
|
281
290
|
) {
|
|
282
291
|
return response[0];
|
|
283
292
|
}
|
|
284
|
-
throw new
|
|
293
|
+
throw new InferenceClientProviderOutputError(
|
|
294
|
+
"Received malformed response from HF-Inference document-question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>"
|
|
295
|
+
);
|
|
285
296
|
}
|
|
286
297
|
}
|
|
287
298
|
|
|
@@ -298,7 +309,9 @@ export class HFInferenceFeatureExtractionTask extends HFInferenceTask implements
|
|
|
298
309
|
if (Array.isArray(response) && isNumArrayRec(response, 3, 0)) {
|
|
299
310
|
return response;
|
|
300
311
|
}
|
|
301
|
-
throw new
|
|
312
|
+
throw new InferenceClientProviderOutputError(
|
|
313
|
+
"Received malformed response from HF-Inference feature-extraction API: expected Array<number[][][] | number[][] | number[] | number>"
|
|
314
|
+
);
|
|
302
315
|
}
|
|
303
316
|
}
|
|
304
317
|
|
|
@@ -307,7 +320,9 @@ export class HFInferenceImageClassificationTask extends HFInferenceTask implemen
|
|
|
307
320
|
if (Array.isArray(response) && response.every((x) => typeof x.label === "string" && typeof x.score === "number")) {
|
|
308
321
|
return response;
|
|
309
322
|
}
|
|
310
|
-
throw new
|
|
323
|
+
throw new InferenceClientProviderOutputError(
|
|
324
|
+
"Received malformed response from HF-Inference image-classification API: expected Array<{label: string, score: number}>"
|
|
325
|
+
);
|
|
311
326
|
}
|
|
312
327
|
}
|
|
313
328
|
|
|
@@ -324,14 +339,18 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements
|
|
|
324
339
|
) {
|
|
325
340
|
return response;
|
|
326
341
|
}
|
|
327
|
-
throw new
|
|
342
|
+
throw new InferenceClientProviderOutputError(
|
|
343
|
+
"Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>"
|
|
344
|
+
);
|
|
328
345
|
}
|
|
329
346
|
}
|
|
330
347
|
|
|
331
348
|
export class HFInferenceImageToTextTask extends HFInferenceTask implements ImageToTextTaskHelper {
|
|
332
349
|
override async getResponse(response: ImageToTextOutput): Promise<ImageToTextOutput> {
|
|
333
350
|
if (typeof response?.generated_text !== "string") {
|
|
334
|
-
throw new
|
|
351
|
+
throw new InferenceClientProviderOutputError(
|
|
352
|
+
"Received malformed response from HF-Inference image-to-text API: expected {generated_text: string}"
|
|
353
|
+
);
|
|
335
354
|
}
|
|
336
355
|
return response;
|
|
337
356
|
}
|
|
@@ -359,7 +378,9 @@ export class HFInferenceImageToImageTask extends HFInferenceTask implements Imag
|
|
|
359
378
|
if (response instanceof Blob) {
|
|
360
379
|
return response;
|
|
361
380
|
}
|
|
362
|
-
throw new
|
|
381
|
+
throw new InferenceClientProviderOutputError(
|
|
382
|
+
"Received malformed response from HF-Inference image-to-image API: expected Blob"
|
|
383
|
+
);
|
|
363
384
|
}
|
|
364
385
|
}
|
|
365
386
|
|
|
@@ -379,8 +400,8 @@ export class HFInferenceObjectDetectionTask extends HFInferenceTask implements O
|
|
|
379
400
|
) {
|
|
380
401
|
return response;
|
|
381
402
|
}
|
|
382
|
-
throw new
|
|
383
|
-
"
|
|
403
|
+
throw new InferenceClientProviderOutputError(
|
|
404
|
+
"Received malformed response from HF-Inference object-detection API: expected Array<{label: string, score: number, box: {xmin: number, ymin: number, xmax: number, ymax: number}}>"
|
|
384
405
|
);
|
|
385
406
|
}
|
|
386
407
|
}
|
|
@@ -393,7 +414,9 @@ export class HFInferenceZeroShotImageClassificationTask
|
|
|
393
414
|
if (Array.isArray(response) && response.every((x) => typeof x.label === "string" && typeof x.score === "number")) {
|
|
394
415
|
return response;
|
|
395
416
|
}
|
|
396
|
-
throw new
|
|
417
|
+
throw new InferenceClientProviderOutputError(
|
|
418
|
+
"Received malformed response from HF-Inference zero-shot-image-classification API: expected Array<{label: string, score: number}>"
|
|
419
|
+
);
|
|
397
420
|
}
|
|
398
421
|
}
|
|
399
422
|
|
|
@@ -403,7 +426,9 @@ export class HFInferenceTextClassificationTask extends HFInferenceTask implement
|
|
|
403
426
|
if (Array.isArray(output) && output.every((x) => typeof x?.label === "string" && typeof x.score === "number")) {
|
|
404
427
|
return output;
|
|
405
428
|
}
|
|
406
|
-
throw new
|
|
429
|
+
throw new InferenceClientProviderOutputError(
|
|
430
|
+
"Received malformed response from HF-Inference text-classification API: expected Array<{label: string, score: number}>"
|
|
431
|
+
);
|
|
407
432
|
}
|
|
408
433
|
}
|
|
409
434
|
|
|
@@ -431,7 +456,9 @@ export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements
|
|
|
431
456
|
) {
|
|
432
457
|
return Array.isArray(response) ? response[0] : response;
|
|
433
458
|
}
|
|
434
|
-
throw new
|
|
459
|
+
throw new InferenceClientProviderOutputError(
|
|
460
|
+
"Received malformed response from HF-Inference question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>"
|
|
461
|
+
);
|
|
435
462
|
}
|
|
436
463
|
}
|
|
437
464
|
|
|
@@ -449,8 +476,8 @@ export class HFInferenceFillMaskTask extends HFInferenceTask implements FillMask
|
|
|
449
476
|
) {
|
|
450
477
|
return response;
|
|
451
478
|
}
|
|
452
|
-
throw new
|
|
453
|
-
"
|
|
479
|
+
throw new InferenceClientProviderOutputError(
|
|
480
|
+
"Received malformed response from HF-Inference fill-mask API: expected Array<{score: number, sequence: string, token: number, token_str: string}>"
|
|
454
481
|
);
|
|
455
482
|
}
|
|
456
483
|
}
|
|
@@ -470,7 +497,9 @@ export class HFInferenceZeroShotClassificationTask extends HFInferenceTask imple
|
|
|
470
497
|
) {
|
|
471
498
|
return response;
|
|
472
499
|
}
|
|
473
|
-
throw new
|
|
500
|
+
throw new InferenceClientProviderOutputError(
|
|
501
|
+
"Received malformed response from HF-Inference zero-shot-classification API: expected Array<{labels: string[], scores: number[], sequence: string}>"
|
|
502
|
+
);
|
|
474
503
|
}
|
|
475
504
|
}
|
|
476
505
|
|
|
@@ -479,7 +508,9 @@ export class HFInferenceSentenceSimilarityTask extends HFInferenceTask implement
|
|
|
479
508
|
if (Array.isArray(response) && response.every((x) => typeof x === "number")) {
|
|
480
509
|
return response;
|
|
481
510
|
}
|
|
482
|
-
throw new
|
|
511
|
+
throw new InferenceClientProviderOutputError(
|
|
512
|
+
"Received malformed response from HF-Inference sentence-similarity API: expected Array<number>"
|
|
513
|
+
);
|
|
483
514
|
}
|
|
484
515
|
}
|
|
485
516
|
|
|
@@ -510,8 +541,8 @@ export class HFInferenceTableQuestionAnsweringTask extends HFInferenceTask imple
|
|
|
510
541
|
) {
|
|
511
542
|
return Array.isArray(response) ? response[0] : response;
|
|
512
543
|
}
|
|
513
|
-
throw new
|
|
514
|
-
"
|
|
544
|
+
throw new InferenceClientProviderOutputError(
|
|
545
|
+
"Received malformed response from HF-Inference table-question-answering API: expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}"
|
|
515
546
|
);
|
|
516
547
|
}
|
|
517
548
|
}
|
|
@@ -531,8 +562,8 @@ export class HFInferenceTokenClassificationTask extends HFInferenceTask implemen
|
|
|
531
562
|
) {
|
|
532
563
|
return response;
|
|
533
564
|
}
|
|
534
|
-
throw new
|
|
535
|
-
"
|
|
565
|
+
throw new InferenceClientProviderOutputError(
|
|
566
|
+
"Received malformed response from HF-Inference token-classification API: expected Array<{end: number, entity_group: string, score: number, start: number, word: string}>"
|
|
536
567
|
);
|
|
537
568
|
}
|
|
538
569
|
}
|
|
@@ -542,7 +573,9 @@ export class HFInferenceTranslationTask extends HFInferenceTask implements Trans
|
|
|
542
573
|
if (Array.isArray(response) && response.every((x) => typeof x?.translation_text === "string")) {
|
|
543
574
|
return response?.length === 1 ? response?.[0] : response;
|
|
544
575
|
}
|
|
545
|
-
throw new
|
|
576
|
+
throw new InferenceClientProviderOutputError(
|
|
577
|
+
"Received malformed response from HF-Inference translation API: expected Array<{translation_text: string}>"
|
|
578
|
+
);
|
|
546
579
|
}
|
|
547
580
|
}
|
|
548
581
|
|
|
@@ -551,7 +584,9 @@ export class HFInferenceSummarizationTask extends HFInferenceTask implements Sum
|
|
|
551
584
|
if (Array.isArray(response) && response.every((x) => typeof x?.summary_text === "string")) {
|
|
552
585
|
return response?.[0];
|
|
553
586
|
}
|
|
554
|
-
throw new
|
|
587
|
+
throw new InferenceClientProviderOutputError(
|
|
588
|
+
"Received malformed response from HF-Inference summarization API: expected Array<{summary_text: string}>"
|
|
589
|
+
);
|
|
555
590
|
}
|
|
556
591
|
}
|
|
557
592
|
|
|
@@ -566,7 +601,9 @@ export class HFInferenceTabularClassificationTask extends HFInferenceTask implem
|
|
|
566
601
|
if (Array.isArray(response) && response.every((x) => typeof x === "number")) {
|
|
567
602
|
return response;
|
|
568
603
|
}
|
|
569
|
-
throw new
|
|
604
|
+
throw new InferenceClientProviderOutputError(
|
|
605
|
+
"Received malformed response from HF-Inference tabular-classification API: expected Array<number>"
|
|
606
|
+
);
|
|
570
607
|
}
|
|
571
608
|
}
|
|
572
609
|
|
|
@@ -584,7 +621,9 @@ export class HFInferenceVisualQuestionAnsweringTask
|
|
|
584
621
|
) {
|
|
585
622
|
return response[0];
|
|
586
623
|
}
|
|
587
|
-
throw new
|
|
624
|
+
throw new InferenceClientProviderOutputError(
|
|
625
|
+
"Received malformed response from HF-Inference visual-question-answering API: expected Array<{answer: string, score: number}>"
|
|
626
|
+
);
|
|
588
627
|
}
|
|
589
628
|
}
|
|
590
629
|
|
|
@@ -593,7 +632,9 @@ export class HFInferenceTabularRegressionTask extends HFInferenceTask implements
|
|
|
593
632
|
if (Array.isArray(response) && response.every((x) => typeof x === "number")) {
|
|
594
633
|
return response;
|
|
595
634
|
}
|
|
596
|
-
throw new
|
|
635
|
+
throw new InferenceClientProviderOutputError(
|
|
636
|
+
"Received malformed response from HF-Inference tabular-regression API: expected Array<number>"
|
|
637
|
+
);
|
|
597
638
|
}
|
|
598
639
|
}
|
|
599
640
|
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
17
|
import type { ChatCompletionOutput, TextGenerationOutput } from "@huggingface/tasks";
|
|
18
|
-
import { InferenceOutputError } from "../lib/InferenceOutputError.js";
|
|
19
18
|
import type { BodyParams, UrlParams } from "../types.js";
|
|
20
19
|
import { omit } from "../utils/omit.js";
|
|
21
20
|
import {
|
|
@@ -24,7 +23,7 @@ import {
|
|
|
24
23
|
TaskProviderHelper,
|
|
25
24
|
type TextToImageTaskHelper,
|
|
26
25
|
} from "./providerHelper.js";
|
|
27
|
-
|
|
26
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
28
27
|
const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
|
|
29
28
|
|
|
30
29
|
export interface HyperbolicTextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
|
|
@@ -79,7 +78,7 @@ export class HyperbolicTextGenerationTask extends BaseTextGenerationTask {
|
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
throw new
|
|
81
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Hyperbolic text generation API");
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
@@ -121,6 +120,6 @@ export class HyperbolicTextToImageTask extends TaskProviderHelper implements Tex
|
|
|
121
120
|
return fetch(`data:image/jpeg;base64,${response.images[0].image}`).then((res) => res.blob());
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
throw new
|
|
123
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Hyperbolic text-to-image API");
|
|
125
124
|
}
|
|
126
125
|
}
|
package/src/providers/nebius.ts
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
17
|
import type { FeatureExtractionOutput } from "@huggingface/tasks";
|
|
18
|
-
import { InferenceOutputError } from "../lib/InferenceOutputError.js";
|
|
19
18
|
import type { BodyParams } from "../types.js";
|
|
20
19
|
import { omit } from "../utils/omit.js";
|
|
21
20
|
import {
|
|
@@ -25,6 +24,7 @@ import {
|
|
|
25
24
|
type FeatureExtractionTaskHelper,
|
|
26
25
|
type TextToImageTaskHelper,
|
|
27
26
|
} from "./providerHelper.js";
|
|
27
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
28
28
|
|
|
29
29
|
const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
|
|
30
30
|
|
|
@@ -92,7 +92,7 @@ export class NebiusTextToImageTask extends TaskProviderHelper implements TextToI
|
|
|
92
92
|
return fetch(`data:image/jpeg;base64,${base64Data}`).then((res) => res.blob());
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
throw new
|
|
95
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Nebius text-to-image API");
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|