@huggingface/inference 4.13.10 → 4.13.12
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 +2 -0
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +4 -0
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/consts.d.ts.map +1 -1
- package/dist/commonjs/providers/consts.js +1 -0
- package/dist/commonjs/providers/nvidia.d.ts +21 -0
- package/dist/commonjs/providers/nvidia.d.ts.map +1 -0
- package/dist/commonjs/providers/nvidia.js +26 -0
- package/dist/commonjs/providers/replicate.d.ts.map +1 -1
- package/dist/commonjs/providers/replicate.js +6 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +11 -20
- package/dist/commonjs/types.d.ts +2 -2
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +2 -0
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +4 -0
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/consts.d.ts.map +1 -1
- package/dist/esm/providers/consts.js +1 -0
- package/dist/esm/providers/nvidia.d.ts +21 -0
- package/dist/esm/providers/nvidia.d.ts.map +1 -0
- package/dist/esm/providers/nvidia.js +22 -0
- package/dist/esm/providers/replicate.d.ts.map +1 -1
- package/dist/esm/providers/replicate.js +6 -1
- package/dist/esm/snippets/getInferenceSnippets.js +11 -20
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +2 -0
- package/package.json +34 -34
- package/src/InferenceClient.ts +2 -2
- package/src/errors.ts +1 -1
- package/src/lib/getDefaultTask.ts +1 -1
- package/src/lib/getInferenceProviderMapping.ts +11 -11
- package/src/lib/getProviderHelper.ts +41 -37
- package/src/lib/makeRequestOptions.ts +11 -11
- package/src/package.ts +1 -1
- package/src/providers/black-forest-labs.ts +3 -3
- package/src/providers/consts.ts +1 -0
- package/src/providers/fal-ai.ts +33 -33
- package/src/providers/featherless-ai.ts +1 -1
- package/src/providers/hf-inference.ts +48 -48
- package/src/providers/hyperbolic.ts +3 -3
- package/src/providers/nebius.ts +1 -1
- package/src/providers/novita.ts +7 -7
- package/src/providers/nscale.ts +2 -2
- package/src/providers/nvidia.ts +23 -0
- package/src/providers/ovhcloud.ts +1 -1
- package/src/providers/providerHelper.ts +7 -7
- package/src/providers/replicate.ts +8 -3
- package/src/providers/sambanova.ts +1 -1
- package/src/providers/together.ts +1 -1
- package/src/providers/wavespeed.ts +10 -10
- package/src/providers/zai-org.ts +7 -7
- package/src/snippets/getInferenceSnippets.ts +26 -26
- package/src/tasks/audio/audioClassification.ts +1 -1
- package/src/tasks/audio/automaticSpeechRecognition.ts +1 -1
- package/src/tasks/audio/utils.ts +1 -1
- package/src/tasks/custom/request.ts +2 -2
- package/src/tasks/custom/streamingRequest.ts +2 -2
- package/src/tasks/cv/imageClassification.ts +1 -1
- package/src/tasks/cv/imageSegmentation.ts +1 -1
- package/src/tasks/cv/textToImage.ts +5 -5
- package/src/tasks/cv/textToVideo.ts +1 -1
- package/src/tasks/cv/zeroShotImageClassification.ts +3 -3
- package/src/tasks/multimodal/documentQuestionAnswering.ts +2 -2
- package/src/tasks/multimodal/visualQuestionAnswering.ts +1 -1
- package/src/tasks/nlp/chatCompletion.ts +1 -1
- package/src/tasks/nlp/chatCompletionStream.ts +1 -1
- package/src/tasks/nlp/featureExtraction.ts +1 -1
- package/src/tasks/nlp/questionAnswering.ts +2 -2
- package/src/tasks/nlp/sentenceSimilarity.ts +1 -1
- package/src/tasks/nlp/tableQuestionAnswering.ts +2 -2
- package/src/tasks/nlp/textClassification.ts +1 -1
- package/src/tasks/nlp/textGeneration.ts +1 -1
- package/src/tasks/nlp/textGenerationStream.ts +1 -1
- package/src/tasks/nlp/tokenClassification.ts +2 -2
- package/src/tasks/nlp/zeroShotClassification.ts +2 -2
- package/src/tasks/tabular/tabularClassification.ts +1 -1
- package/src/tasks/tabular/tabularRegression.ts +1 -1
- package/src/types.ts +2 -0
- package/src/utils/pick.ts +1 -1
- package/src/utils/request.ts +20 -20
- package/src/utils/typedEntries.ts +1 -1
package/src/providers/fal-ai.ts
CHANGED
|
@@ -106,7 +106,7 @@ abstract class FalAiQueueTask extends FalAITask {
|
|
|
106
106
|
async getResponseFromQueueApi(
|
|
107
107
|
response: FalAiQueueOutput,
|
|
108
108
|
url?: string,
|
|
109
|
-
headers?: Record<string, string
|
|
109
|
+
headers?: Record<string, string>,
|
|
110
110
|
): Promise<unknown> {
|
|
111
111
|
if (!url || !headers) {
|
|
112
112
|
throw new InferenceClientInputError(`URL and headers are required for ${this.task} task`);
|
|
@@ -114,7 +114,7 @@ abstract class FalAiQueueTask extends FalAITask {
|
|
|
114
114
|
const requestId = response.request_id;
|
|
115
115
|
if (!requestId) {
|
|
116
116
|
throw new InferenceClientProviderOutputError(
|
|
117
|
-
`Received malformed response from Fal.ai ${this.task} API: no request ID found in the response
|
|
117
|
+
`Received malformed response from Fal.ai ${this.task} API: no request ID found in the response`,
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
let status = response.status;
|
|
@@ -144,14 +144,14 @@ abstract class FalAiQueueTask extends FalAITask {
|
|
|
144
144
|
requestId: statusResponse.headers.get("x-request-id") ?? "",
|
|
145
145
|
status: statusResponse.status,
|
|
146
146
|
body: await statusResponse.text(),
|
|
147
|
-
}
|
|
147
|
+
},
|
|
148
148
|
);
|
|
149
149
|
}
|
|
150
150
|
try {
|
|
151
151
|
status = (await statusResponse.json()).status;
|
|
152
152
|
} catch (error) {
|
|
153
153
|
throw new InferenceClientProviderOutputError(
|
|
154
|
-
"Failed to parse status response from fal-ai API: received malformed response"
|
|
154
|
+
"Failed to parse status response from fal-ai API: received malformed response",
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -162,7 +162,7 @@ abstract class FalAiQueueTask extends FalAITask {
|
|
|
162
162
|
result = await resultResponse.json();
|
|
163
163
|
} catch (error) {
|
|
164
164
|
throw new InferenceClientProviderOutputError(
|
|
165
|
-
"Failed to parse result response from fal-ai API: received malformed response"
|
|
165
|
+
"Failed to parse result response from fal-ai API: received malformed response",
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
return result;
|
|
@@ -207,7 +207,7 @@ export class FalAITextToImageTask extends FalAiQueueTask implements TextToImageT
|
|
|
207
207
|
response: FalAiQueueOutput,
|
|
208
208
|
url?: string,
|
|
209
209
|
headers?: Record<string, string>,
|
|
210
|
-
outputType?: OutputType
|
|
210
|
+
outputType?: OutputType,
|
|
211
211
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
212
212
|
const result = (await this.getResponseFromQueueApi(response, url, headers)) as FalAITextToImageOutput;
|
|
213
213
|
if (
|
|
@@ -232,8 +232,8 @@ export class FalAITextToImageTask extends FalAiQueueTask implements TextToImageT
|
|
|
232
232
|
|
|
233
233
|
throw new InferenceClientProviderOutputError(
|
|
234
234
|
`Received malformed response from Fal.ai text-to-image API: expected { images: Array<{ url: string }> } result format, got instead: ${JSON.stringify(
|
|
235
|
-
result
|
|
236
|
-
)}
|
|
235
|
+
result,
|
|
236
|
+
)}`,
|
|
237
237
|
);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -261,7 +261,7 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag
|
|
|
261
261
|
async preparePayloadAsync(args: ImageToImageArgs): Promise<RequestArgs> {
|
|
262
262
|
const mimeType = args.inputs instanceof Blob ? args.inputs.type : "image/png";
|
|
263
263
|
const imageDataUrl = `data:${mimeType};base64,${base64FromBytes(
|
|
264
|
-
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer())
|
|
264
|
+
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()),
|
|
265
265
|
)}`;
|
|
266
266
|
return {
|
|
267
267
|
...omit(args, ["inputs", "parameters"]),
|
|
@@ -276,7 +276,7 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag
|
|
|
276
276
|
override async getResponse(
|
|
277
277
|
response: FalAiQueueOutput,
|
|
278
278
|
url?: string,
|
|
279
|
-
headers?: Record<string, string
|
|
279
|
+
headers?: Record<string, string>,
|
|
280
280
|
): Promise<Blob> {
|
|
281
281
|
const result = await this.getResponseFromQueueApi(response, url, headers);
|
|
282
282
|
|
|
@@ -297,8 +297,8 @@ export class FalAIImageToImageTask extends FalAiQueueTask implements ImageToImag
|
|
|
297
297
|
} else {
|
|
298
298
|
throw new InferenceClientProviderOutputError(
|
|
299
299
|
`Received malformed response from Fal.ai image-to-image API: expected { images: Array<{ url: string }> } result format, got instead: ${JSON.stringify(
|
|
300
|
-
result
|
|
301
|
-
)}
|
|
300
|
+
result,
|
|
301
|
+
)}`,
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
@@ -346,7 +346,7 @@ export class FalAITextToVideoTask extends FalAiQueueTask implements TextToVideoT
|
|
|
346
346
|
override async getResponse(
|
|
347
347
|
response: FalAiQueueOutput,
|
|
348
348
|
url?: string,
|
|
349
|
-
headers?: Record<string, string
|
|
349
|
+
headers?: Record<string, string>,
|
|
350
350
|
): Promise<Blob> {
|
|
351
351
|
const result = await this.getResponseFromQueueApi(response, url, headers);
|
|
352
352
|
|
|
@@ -365,8 +365,8 @@ export class FalAITextToVideoTask extends FalAiQueueTask implements TextToVideoT
|
|
|
365
365
|
} else {
|
|
366
366
|
throw new InferenceClientProviderOutputError(
|
|
367
367
|
`Received malformed response from Fal.ai text-to-video API: expected { video: { url: string } } result format, got instead: ${JSON.stringify(
|
|
368
|
-
result
|
|
369
|
-
)}
|
|
368
|
+
result,
|
|
369
|
+
)}`,
|
|
370
370
|
);
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -396,7 +396,7 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide
|
|
|
396
396
|
return {
|
|
397
397
|
...omit(args, ["inputs", "parameters"]),
|
|
398
398
|
image_url: `data:${mimeType};base64,${base64FromBytes(
|
|
399
|
-
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer())
|
|
399
|
+
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()),
|
|
400
400
|
)}`,
|
|
401
401
|
...args.parameters,
|
|
402
402
|
...args,
|
|
@@ -407,7 +407,7 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide
|
|
|
407
407
|
override async getResponse(
|
|
408
408
|
response: FalAiQueueOutput,
|
|
409
409
|
url?: string,
|
|
410
|
-
headers?: Record<string, string
|
|
410
|
+
headers?: Record<string, string>,
|
|
411
411
|
): Promise<Blob> {
|
|
412
412
|
const result = await this.getResponseFromQueueApi(response, url, headers);
|
|
413
413
|
|
|
@@ -428,8 +428,8 @@ export class FalAIImageToVideoTask extends FalAiQueueTask implements ImageToVide
|
|
|
428
428
|
|
|
429
429
|
throw new InferenceClientProviderOutputError(
|
|
430
430
|
`Received malformed response from Fal.ai image‑to‑video API: expected { video: { url: string } }, got: ${JSON.stringify(
|
|
431
|
-
result
|
|
432
|
-
)}
|
|
431
|
+
result,
|
|
432
|
+
)}`,
|
|
433
433
|
);
|
|
434
434
|
}
|
|
435
435
|
}
|
|
@@ -468,8 +468,8 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au
|
|
|
468
468
|
if (typeof res?.text !== "string") {
|
|
469
469
|
throw new InferenceClientProviderOutputError(
|
|
470
470
|
`Received malformed response from Fal.ai Automatic Speech Recognition API: expected { text: string } format, got instead: ${JSON.stringify(
|
|
471
|
-
response
|
|
472
|
-
)}
|
|
471
|
+
response,
|
|
472
|
+
)}`,
|
|
473
473
|
);
|
|
474
474
|
}
|
|
475
475
|
return { text: res.text };
|
|
@@ -480,14 +480,14 @@ export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements Au
|
|
|
480
480
|
const contentType = blob?.type;
|
|
481
481
|
if (!contentType) {
|
|
482
482
|
throw new InferenceClientInputError(
|
|
483
|
-
`Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai
|
|
483
|
+
`Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai.`,
|
|
484
484
|
);
|
|
485
485
|
}
|
|
486
486
|
if (!FAL_AI_SUPPORTED_BLOB_TYPES.includes(contentType)) {
|
|
487
487
|
throw new InferenceClientInputError(
|
|
488
488
|
`Provider fal-ai does not support blob type ${contentType} - supported content types are: ${FAL_AI_SUPPORTED_BLOB_TYPES.join(
|
|
489
|
-
", "
|
|
490
|
-
)}
|
|
489
|
+
", ",
|
|
490
|
+
)}`,
|
|
491
491
|
);
|
|
492
492
|
}
|
|
493
493
|
const base64audio = base64FromBytes(new Uint8Array(await blob.arrayBuffer()));
|
|
@@ -512,8 +512,8 @@ export class FalAITextToSpeechTask extends FalAITask {
|
|
|
512
512
|
if (typeof res?.audio?.url !== "string") {
|
|
513
513
|
throw new InferenceClientProviderOutputError(
|
|
514
514
|
`Received malformed response from Fal.ai Text-to-Speech API: expected { audio: { url: string } } format, got instead: ${JSON.stringify(
|
|
515
|
-
response
|
|
516
|
-
)}
|
|
515
|
+
response,
|
|
516
|
+
)}`,
|
|
517
517
|
);
|
|
518
518
|
}
|
|
519
519
|
const urlResponse = await fetch(res.audio.url);
|
|
@@ -525,7 +525,7 @@ export class FalAITextToSpeechTask extends FalAITask {
|
|
|
525
525
|
requestId: urlResponse.headers.get("x-request-id") ?? "",
|
|
526
526
|
status: urlResponse.status,
|
|
527
527
|
body: await urlResponse.text(),
|
|
528
|
-
}
|
|
528
|
+
},
|
|
529
529
|
);
|
|
530
530
|
}
|
|
531
531
|
try {
|
|
@@ -538,7 +538,7 @@ export class FalAITextToSpeechTask extends FalAITask {
|
|
|
538
538
|
requestId: urlResponse.headers.get("x-request-id") ?? "",
|
|
539
539
|
status: urlResponse.status,
|
|
540
540
|
body: await urlResponse.text(),
|
|
541
|
-
}
|
|
541
|
+
},
|
|
542
542
|
);
|
|
543
543
|
}
|
|
544
544
|
}
|
|
@@ -562,7 +562,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS
|
|
|
562
562
|
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
563
563
|
const mimeType = blob instanceof Blob ? blob.type : "image/png";
|
|
564
564
|
const base64Image = base64FromBytes(
|
|
565
|
-
new Uint8Array(blob instanceof ArrayBuffer ? blob : await (blob as Blob).arrayBuffer())
|
|
565
|
+
new Uint8Array(blob instanceof ArrayBuffer ? blob : await (blob as Blob).arrayBuffer()),
|
|
566
566
|
);
|
|
567
567
|
return {
|
|
568
568
|
...omit(args, ["inputs", "parameters", "data"]),
|
|
@@ -576,7 +576,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS
|
|
|
576
576
|
override async getResponse(
|
|
577
577
|
response: FalAiQueueOutput,
|
|
578
578
|
url?: string,
|
|
579
|
-
headers?: Record<string, string
|
|
579
|
+
headers?: Record<string, string>,
|
|
580
580
|
): Promise<ImageSegmentationOutput> {
|
|
581
581
|
const result = await this.getResponseFromQueueApi(response, url, headers);
|
|
582
582
|
if (
|
|
@@ -597,7 +597,7 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS
|
|
|
597
597
|
requestId: maskResponse.headers.get("x-request-id") ?? "",
|
|
598
598
|
status: maskResponse.status,
|
|
599
599
|
body: await maskResponse.text(),
|
|
600
|
-
}
|
|
600
|
+
},
|
|
601
601
|
);
|
|
602
602
|
}
|
|
603
603
|
const maskBlob = await maskResponse.blob();
|
|
@@ -615,8 +615,8 @@ export class FalAIImageSegmentationTask extends FalAiQueueTask implements ImageS
|
|
|
615
615
|
|
|
616
616
|
throw new InferenceClientProviderOutputError(
|
|
617
617
|
`Received malformed response from Fal.ai image-segmentation API: expected { image: { url: string } } format, got instead: ${JSON.stringify(
|
|
618
|
-
response
|
|
619
|
-
)}
|
|
618
|
+
response,
|
|
619
|
+
)}`,
|
|
620
620
|
);
|
|
621
621
|
}
|
|
622
622
|
}
|
|
@@ -127,7 +127,7 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT
|
|
|
127
127
|
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
128
128
|
if (params.outputType === "url") {
|
|
129
129
|
throw new InferenceClientInputError(
|
|
130
|
-
"hf-inference provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead."
|
|
130
|
+
"hf-inference provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.",
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
133
|
return params.args;
|
|
@@ -137,11 +137,11 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT
|
|
|
137
137
|
response: Base64ImageGeneration | OutputUrlImageGeneration,
|
|
138
138
|
url?: string,
|
|
139
139
|
headers?: HeadersInit,
|
|
140
|
-
outputType?: OutputType
|
|
140
|
+
outputType?: OutputType,
|
|
141
141
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
142
142
|
if (!response) {
|
|
143
143
|
throw new InferenceClientProviderOutputError(
|
|
144
|
-
"Received malformed response from HF-Inference text-to-image API: response is undefined"
|
|
144
|
+
"Received malformed response from HF-Inference text-to-image API: response is undefined",
|
|
145
145
|
);
|
|
146
146
|
}
|
|
147
147
|
if (typeof response == "object") {
|
|
@@ -172,7 +172,7 @@ export class HFInferenceTextToImageTask extends HFInferenceTask implements TextT
|
|
|
172
172
|
return response;
|
|
173
173
|
}
|
|
174
174
|
throw new InferenceClientProviderOutputError(
|
|
175
|
-
"Received malformed response from HF-Inference text-to-image API: expected a Blob"
|
|
175
|
+
"Received malformed response from HF-Inference text-to-image API: expected a Blob",
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -215,7 +215,7 @@ export class HFInferenceTextGenerationTask extends HFInferenceTask implements Te
|
|
|
215
215
|
return (res as TextGenerationOutput[])?.[0];
|
|
216
216
|
}
|
|
217
217
|
throw new InferenceClientProviderOutputError(
|
|
218
|
-
"Received malformed response from HF-Inference text generation API: expected Array<{generated_text: string}>"
|
|
218
|
+
"Received malformed response from HF-Inference text generation API: expected Array<{generated_text: string}>",
|
|
219
219
|
);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -226,13 +226,13 @@ export class HFInferenceAudioClassificationTask extends HFInferenceTask implemen
|
|
|
226
226
|
Array.isArray(response) &&
|
|
227
227
|
response.every(
|
|
228
228
|
(x): x is { label: string; score: number } =>
|
|
229
|
-
typeof x === "object" && x !== null && typeof x.label === "string" && typeof x.score === "number"
|
|
229
|
+
typeof x === "object" && x !== null && typeof x.label === "string" && typeof x.score === "number",
|
|
230
230
|
)
|
|
231
231
|
) {
|
|
232
232
|
return response;
|
|
233
233
|
}
|
|
234
234
|
throw new InferenceClientProviderOutputError(
|
|
235
|
-
"Received malformed response from HF-Inference audio-classification API: expected Array<{label: string, score: number}> but received different format"
|
|
235
|
+
"Received malformed response from HF-Inference audio-classification API: expected Array<{label: string, score: number}> but received different format",
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -251,7 +251,7 @@ export class HFInferenceAutomaticSpeechRecognitionTask
|
|
|
251
251
|
: {
|
|
252
252
|
...omit(args, "inputs"),
|
|
253
253
|
data: args.inputs,
|
|
254
|
-
|
|
254
|
+
};
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
|
|
@@ -259,7 +259,7 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi
|
|
|
259
259
|
override async getResponse(response: AudioToAudioOutput[]): Promise<AudioToAudioOutput[]> {
|
|
260
260
|
if (!Array.isArray(response)) {
|
|
261
261
|
throw new InferenceClientProviderOutputError(
|
|
262
|
-
"Received malformed response from HF-Inference audio-to-audio API: expected Array"
|
|
262
|
+
"Received malformed response from HF-Inference audio-to-audio API: expected Array",
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
265
|
if (
|
|
@@ -277,7 +277,7 @@ export class HFInferenceAudioToAudioTask extends HFInferenceTask implements Audi
|
|
|
277
277
|
})
|
|
278
278
|
) {
|
|
279
279
|
throw new InferenceClientProviderOutputError(
|
|
280
|
-
"Received malformed response from HF-Inference audio-to-audio API: expected Array<{label: string, audio: Blob}>"
|
|
280
|
+
"Received malformed response from HF-Inference audio-to-audio API: expected Array<{label: string, audio: Blob}>",
|
|
281
281
|
);
|
|
282
282
|
}
|
|
283
283
|
return response;
|
|
@@ -289,7 +289,7 @@ export class HFInferenceDocumentQuestionAnsweringTask
|
|
|
289
289
|
implements DocumentQuestionAnsweringTaskHelper
|
|
290
290
|
{
|
|
291
291
|
override async getResponse(
|
|
292
|
-
response: DocumentQuestionAnsweringOutput
|
|
292
|
+
response: DocumentQuestionAnsweringOutput,
|
|
293
293
|
): Promise<DocumentQuestionAnsweringOutput[number]> {
|
|
294
294
|
if (
|
|
295
295
|
Array.isArray(response) &&
|
|
@@ -300,13 +300,13 @@ export class HFInferenceDocumentQuestionAnsweringTask
|
|
|
300
300
|
typeof elem?.answer === "string" &&
|
|
301
301
|
(typeof elem.end === "number" || typeof elem.end === "undefined") &&
|
|
302
302
|
(typeof elem.score === "number" || typeof elem.score === "undefined") &&
|
|
303
|
-
(typeof elem.start === "number" || typeof elem.start === "undefined")
|
|
303
|
+
(typeof elem.start === "number" || typeof elem.start === "undefined"),
|
|
304
304
|
)
|
|
305
305
|
) {
|
|
306
306
|
return response[0];
|
|
307
307
|
}
|
|
308
308
|
throw new InferenceClientProviderOutputError(
|
|
309
|
-
"Received malformed response from HF-Inference document-question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>"
|
|
309
|
+
"Received malformed response from HF-Inference document-question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>",
|
|
310
310
|
);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
@@ -325,7 +325,7 @@ export class HFInferenceFeatureExtractionTask extends HFInferenceTask implements
|
|
|
325
325
|
return response;
|
|
326
326
|
}
|
|
327
327
|
throw new InferenceClientProviderOutputError(
|
|
328
|
-
"Received malformed response from HF-Inference feature-extraction API: expected Array<number[][][] | number[][] | number[] | number>"
|
|
328
|
+
"Received malformed response from HF-Inference feature-extraction API: expected Array<number[][][] | number[][] | number[] | number>",
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
@@ -336,7 +336,7 @@ export class HFInferenceImageClassificationTask extends HFInferenceTask implemen
|
|
|
336
336
|
return response;
|
|
337
337
|
}
|
|
338
338
|
throw new InferenceClientProviderOutputError(
|
|
339
|
-
"Received malformed response from HF-Inference image-classification API: expected Array<{label: string, score: number}>"
|
|
339
|
+
"Received malformed response from HF-Inference image-classification API: expected Array<{label: string, score: number}>",
|
|
340
340
|
);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -349,13 +349,13 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements
|
|
|
349
349
|
(x) =>
|
|
350
350
|
typeof x.label === "string" &&
|
|
351
351
|
typeof x.mask === "string" &&
|
|
352
|
-
(x.score === undefined || typeof x.score === "number")
|
|
352
|
+
(x.score === undefined || typeof x.score === "number"),
|
|
353
353
|
)
|
|
354
354
|
) {
|
|
355
355
|
return response;
|
|
356
356
|
}
|
|
357
357
|
throw new InferenceClientProviderOutputError(
|
|
358
|
-
"Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>"
|
|
358
|
+
"Received malformed response from HF-Inference image-segmentation API: expected Array<{label: string, mask: string, score: number}>",
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
|
|
@@ -363,7 +363,7 @@ export class HFInferenceImageSegmentationTask extends HFInferenceTask implements
|
|
|
363
363
|
return {
|
|
364
364
|
...args,
|
|
365
365
|
inputs: base64FromBytes(
|
|
366
|
-
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer())
|
|
366
|
+
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()),
|
|
367
367
|
),
|
|
368
368
|
};
|
|
369
369
|
}
|
|
@@ -373,7 +373,7 @@ export class HFInferenceImageToTextTask extends HFInferenceTask implements Image
|
|
|
373
373
|
override async getResponse(response: ImageToTextOutput): Promise<ImageToTextOutput> {
|
|
374
374
|
if (typeof response?.generated_text !== "string") {
|
|
375
375
|
throw new InferenceClientProviderOutputError(
|
|
376
|
-
"Received malformed response from HF-Inference image-to-text API: expected {generated_text: string}"
|
|
376
|
+
"Received malformed response from HF-Inference image-to-text API: expected {generated_text: string}",
|
|
377
377
|
);
|
|
378
378
|
}
|
|
379
379
|
return response;
|
|
@@ -392,7 +392,7 @@ export class HFInferenceImageToImageTask extends HFInferenceTask implements Imag
|
|
|
392
392
|
return {
|
|
393
393
|
...args,
|
|
394
394
|
inputs: base64FromBytes(
|
|
395
|
-
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer())
|
|
395
|
+
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer()),
|
|
396
396
|
),
|
|
397
397
|
};
|
|
398
398
|
}
|
|
@@ -403,7 +403,7 @@ export class HFInferenceImageToImageTask extends HFInferenceTask implements Imag
|
|
|
403
403
|
return response;
|
|
404
404
|
}
|
|
405
405
|
throw new InferenceClientProviderOutputError(
|
|
406
|
-
"Received malformed response from HF-Inference image-to-image API: expected Blob"
|
|
406
|
+
"Received malformed response from HF-Inference image-to-image API: expected Blob",
|
|
407
407
|
);
|
|
408
408
|
}
|
|
409
409
|
}
|
|
@@ -419,13 +419,13 @@ export class HFInferenceObjectDetectionTask extends HFInferenceTask implements O
|
|
|
419
419
|
typeof x.box.xmin === "number" &&
|
|
420
420
|
typeof x.box.ymin === "number" &&
|
|
421
421
|
typeof x.box.xmax === "number" &&
|
|
422
|
-
typeof x.box.ymax === "number"
|
|
422
|
+
typeof x.box.ymax === "number",
|
|
423
423
|
)
|
|
424
424
|
) {
|
|
425
425
|
return response;
|
|
426
426
|
}
|
|
427
427
|
throw new InferenceClientProviderOutputError(
|
|
428
|
-
"Received malformed response from HF-Inference object-detection API: expected Array<{label: string, score: number, box: {xmin: number, ymin: number, xmax: number, ymax: number}}>"
|
|
428
|
+
"Received malformed response from HF-Inference object-detection API: expected Array<{label: string, score: number, box: {xmin: number, ymin: number, xmax: number, ymax: number}}>",
|
|
429
429
|
);
|
|
430
430
|
}
|
|
431
431
|
}
|
|
@@ -439,7 +439,7 @@ export class HFInferenceZeroShotImageClassificationTask
|
|
|
439
439
|
return response;
|
|
440
440
|
}
|
|
441
441
|
throw new InferenceClientProviderOutputError(
|
|
442
|
-
"Received malformed response from HF-Inference zero-shot-image-classification API: expected Array<{label: string, score: number}>"
|
|
442
|
+
"Received malformed response from HF-Inference zero-shot-image-classification API: expected Array<{label: string, score: number}>",
|
|
443
443
|
);
|
|
444
444
|
}
|
|
445
445
|
}
|
|
@@ -451,14 +451,14 @@ export class HFInferenceTextClassificationTask extends HFInferenceTask implement
|
|
|
451
451
|
return output;
|
|
452
452
|
}
|
|
453
453
|
throw new InferenceClientProviderOutputError(
|
|
454
|
-
"Received malformed response from HF-Inference text-classification API: expected Array<{label: string, score: number}>"
|
|
454
|
+
"Received malformed response from HF-Inference text-classification API: expected Array<{label: string, score: number}>",
|
|
455
455
|
);
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
|
|
459
459
|
export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements QuestionAnsweringTaskHelper {
|
|
460
460
|
override async getResponse(
|
|
461
|
-
response: QuestionAnsweringOutput | QuestionAnsweringOutput[number]
|
|
461
|
+
response: QuestionAnsweringOutput | QuestionAnsweringOutput[number],
|
|
462
462
|
): Promise<QuestionAnsweringOutputElement> {
|
|
463
463
|
if (
|
|
464
464
|
Array.isArray(response)
|
|
@@ -469,19 +469,19 @@ export class HFInferenceQuestionAnsweringTask extends HFInferenceTask implements
|
|
|
469
469
|
typeof elem.answer === "string" &&
|
|
470
470
|
typeof elem.end === "number" &&
|
|
471
471
|
typeof elem.score === "number" &&
|
|
472
|
-
typeof elem.start === "number"
|
|
473
|
-
|
|
472
|
+
typeof elem.start === "number",
|
|
473
|
+
)
|
|
474
474
|
: typeof response === "object" &&
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
475
|
+
!!response &&
|
|
476
|
+
typeof response.answer === "string" &&
|
|
477
|
+
typeof response.end === "number" &&
|
|
478
|
+
typeof response.score === "number" &&
|
|
479
|
+
typeof response.start === "number"
|
|
480
480
|
) {
|
|
481
481
|
return Array.isArray(response) ? response[0] : response;
|
|
482
482
|
}
|
|
483
483
|
throw new InferenceClientProviderOutputError(
|
|
484
|
-
"Received malformed response from HF-Inference question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>"
|
|
484
|
+
"Received malformed response from HF-Inference question-answering API: expected Array<{answer: string, end: number, score: number, start: number}>",
|
|
485
485
|
);
|
|
486
486
|
}
|
|
487
487
|
}
|
|
@@ -495,13 +495,13 @@ export class HFInferenceFillMaskTask extends HFInferenceTask implements FillMask
|
|
|
495
495
|
typeof x.score === "number" &&
|
|
496
496
|
typeof x.sequence === "string" &&
|
|
497
497
|
typeof x.token === "number" &&
|
|
498
|
-
typeof x.token_str === "string"
|
|
498
|
+
typeof x.token_str === "string",
|
|
499
499
|
)
|
|
500
500
|
) {
|
|
501
501
|
return response;
|
|
502
502
|
}
|
|
503
503
|
throw new InferenceClientProviderOutputError(
|
|
504
|
-
"Received malformed response from HF-Inference fill-mask API: expected Array<{score: number, sequence: string, token: number, token_str: string}>"
|
|
504
|
+
"Received malformed response from HF-Inference fill-mask API: expected Array<{score: number, sequence: string, token: number, token_str: string}>",
|
|
505
505
|
);
|
|
506
506
|
}
|
|
507
507
|
}
|
|
@@ -531,7 +531,7 @@ export class HFInferenceZeroShotClassificationTask extends HFInferenceTask imple
|
|
|
531
531
|
return response;
|
|
532
532
|
}
|
|
533
533
|
throw new InferenceClientProviderOutputError(
|
|
534
|
-
"Received malformed response from HF-Inference zero-shot-classification API: expected Array<{label: string, score: number}>"
|
|
534
|
+
"Received malformed response from HF-Inference zero-shot-classification API: expected Array<{label: string, score: number}>",
|
|
535
535
|
);
|
|
536
536
|
}
|
|
537
537
|
|
|
@@ -553,7 +553,7 @@ export class HFInferenceSentenceSimilarityTask extends HFInferenceTask implement
|
|
|
553
553
|
return response;
|
|
554
554
|
}
|
|
555
555
|
throw new InferenceClientProviderOutputError(
|
|
556
|
-
"Received malformed response from HF-Inference sentence-similarity API: expected Array<number>"
|
|
556
|
+
"Received malformed response from HF-Inference sentence-similarity API: expected Array<number>",
|
|
557
557
|
);
|
|
558
558
|
}
|
|
559
559
|
}
|
|
@@ -573,7 +573,7 @@ export class HFInferenceTableQuestionAnsweringTask extends HFInferenceTask imple
|
|
|
573
573
|
"coordinates" in elem &&
|
|
574
574
|
Array.isArray(elem.coordinates) &&
|
|
575
575
|
elem.coordinates.every(
|
|
576
|
-
(coord: unknown): coord is number[] => Array.isArray(coord) && coord.every((x) => typeof x === "number")
|
|
576
|
+
(coord: unknown): coord is number[] => Array.isArray(coord) && coord.every((x) => typeof x === "number"),
|
|
577
577
|
)
|
|
578
578
|
);
|
|
579
579
|
}
|
|
@@ -586,7 +586,7 @@ export class HFInferenceTableQuestionAnsweringTask extends HFInferenceTask imple
|
|
|
586
586
|
return Array.isArray(response) ? response[0] : response;
|
|
587
587
|
}
|
|
588
588
|
throw new InferenceClientProviderOutputError(
|
|
589
|
-
"Received malformed response from HF-Inference table-question-answering API: expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}"
|
|
589
|
+
"Received malformed response from HF-Inference table-question-answering API: expected {aggregator: string, answer: string, cells: string[], coordinates: number[][]}",
|
|
590
590
|
);
|
|
591
591
|
}
|
|
592
592
|
}
|
|
@@ -601,13 +601,13 @@ export class HFInferenceTokenClassificationTask extends HFInferenceTask implemen
|
|
|
601
601
|
typeof x.entity_group === "string" &&
|
|
602
602
|
typeof x.score === "number" &&
|
|
603
603
|
typeof x.start === "number" &&
|
|
604
|
-
typeof x.word === "string"
|
|
604
|
+
typeof x.word === "string",
|
|
605
605
|
)
|
|
606
606
|
) {
|
|
607
607
|
return response;
|
|
608
608
|
}
|
|
609
609
|
throw new InferenceClientProviderOutputError(
|
|
610
|
-
"Received malformed response from HF-Inference token-classification API: expected Array<{end: number, entity_group: string, score: number, start: number, word: string}>"
|
|
610
|
+
"Received malformed response from HF-Inference token-classification API: expected Array<{end: number, entity_group: string, score: number, start: number, word: string}>",
|
|
611
611
|
);
|
|
612
612
|
}
|
|
613
613
|
}
|
|
@@ -618,7 +618,7 @@ export class HFInferenceTranslationTask extends HFInferenceTask implements Trans
|
|
|
618
618
|
return response?.length === 1 ? response?.[0] : response;
|
|
619
619
|
}
|
|
620
620
|
throw new InferenceClientProviderOutputError(
|
|
621
|
-
"Received malformed response from HF-Inference translation API: expected Array<{translation_text: string}>"
|
|
621
|
+
"Received malformed response from HF-Inference translation API: expected Array<{translation_text: string}>",
|
|
622
622
|
);
|
|
623
623
|
}
|
|
624
624
|
}
|
|
@@ -629,7 +629,7 @@ export class HFInferenceSummarizationTask extends HFInferenceTask implements Sum
|
|
|
629
629
|
return response?.[0];
|
|
630
630
|
}
|
|
631
631
|
throw new InferenceClientProviderOutputError(
|
|
632
|
-
"Received malformed response from HF-Inference summarization API: expected Array<{summary_text: string}>"
|
|
632
|
+
"Received malformed response from HF-Inference summarization API: expected Array<{summary_text: string}>",
|
|
633
633
|
);
|
|
634
634
|
}
|
|
635
635
|
}
|
|
@@ -646,7 +646,7 @@ export class HFInferenceTabularClassificationTask extends HFInferenceTask implem
|
|
|
646
646
|
return response;
|
|
647
647
|
}
|
|
648
648
|
throw new InferenceClientProviderOutputError(
|
|
649
|
-
"Received malformed response from HF-Inference tabular-classification API: expected Array<number>"
|
|
649
|
+
"Received malformed response from HF-Inference tabular-classification API: expected Array<number>",
|
|
650
650
|
);
|
|
651
651
|
}
|
|
652
652
|
}
|
|
@@ -660,13 +660,13 @@ export class HFInferenceVisualQuestionAnsweringTask
|
|
|
660
660
|
Array.isArray(response) &&
|
|
661
661
|
response.every(
|
|
662
662
|
(elem) =>
|
|
663
|
-
typeof elem === "object" && !!elem && typeof elem?.answer === "string" && typeof elem.score === "number"
|
|
663
|
+
typeof elem === "object" && !!elem && typeof elem?.answer === "string" && typeof elem.score === "number",
|
|
664
664
|
)
|
|
665
665
|
) {
|
|
666
666
|
return response[0];
|
|
667
667
|
}
|
|
668
668
|
throw new InferenceClientProviderOutputError(
|
|
669
|
-
"Received malformed response from HF-Inference visual-question-answering API: expected Array<{answer: string, score: number}>"
|
|
669
|
+
"Received malformed response from HF-Inference visual-question-answering API: expected Array<{answer: string, score: number}>",
|
|
670
670
|
);
|
|
671
671
|
}
|
|
672
672
|
}
|
|
@@ -677,7 +677,7 @@ export class HFInferenceTabularRegressionTask extends HFInferenceTask implements
|
|
|
677
677
|
return response;
|
|
678
678
|
}
|
|
679
679
|
throw new InferenceClientProviderOutputError(
|
|
680
|
-
"Received malformed response from HF-Inference tabular-regression API: expected Array<number>"
|
|
680
|
+
"Received malformed response from HF-Inference tabular-regression API: expected Array<number>",
|
|
681
681
|
);
|
|
682
682
|
}
|
|
683
683
|
}
|
|
@@ -58,7 +58,7 @@ export class HyperbolicTextGenerationTask extends BaseTextGenerationTask {
|
|
|
58
58
|
? {
|
|
59
59
|
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
|
|
60
60
|
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
|
|
61
|
-
|
|
61
|
+
}
|
|
62
62
|
: undefined),
|
|
63
63
|
...omit(params.args, ["inputs", "parameters"]),
|
|
64
64
|
model: params.model,
|
|
@@ -95,7 +95,7 @@ export class HyperbolicTextToImageTask extends TaskProviderHelper implements Tex
|
|
|
95
95
|
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
96
96
|
if (params.outputType === "url") {
|
|
97
97
|
throw new InferenceClientInputError(
|
|
98
|
-
"hyperbolic provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead."
|
|
98
|
+
"hyperbolic provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.",
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
101
|
return {
|
|
@@ -110,7 +110,7 @@ export class HyperbolicTextToImageTask extends TaskProviderHelper implements Tex
|
|
|
110
110
|
response: HyperbolicTextToImageOutput,
|
|
111
111
|
url?: string,
|
|
112
112
|
headers?: HeadersInit,
|
|
113
|
-
outputType?: OutputType
|
|
113
|
+
outputType?: OutputType,
|
|
114
114
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
115
115
|
if (
|
|
116
116
|
typeof response === "object" &&
|
package/src/providers/nebius.ts
CHANGED
|
@@ -117,7 +117,7 @@ export class NebiusTextToImageTask extends TaskProviderHelper implements TextToI
|
|
|
117
117
|
response: NebiusImageGeneration,
|
|
118
118
|
url?: string,
|
|
119
119
|
headers?: HeadersInit,
|
|
120
|
-
outputType?: OutputType
|
|
120
|
+
outputType?: OutputType,
|
|
121
121
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
122
122
|
if (
|
|
123
123
|
typeof response === "object" &&
|