@huggingface/inference 4.13.10 → 4.13.11
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/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- 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/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- 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/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 +37 -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/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/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/utils/pick.ts +1 -1
- package/src/utils/request.ts +20 -20
- package/src/utils/typedEntries.ts +1 -1
|
@@ -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" &&
|
package/src/providers/novita.ts
CHANGED
|
@@ -79,7 +79,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
|
|
|
79
79
|
override async getResponse(
|
|
80
80
|
response: NovitaAsyncAPIOutput,
|
|
81
81
|
url?: string,
|
|
82
|
-
headers?: Record<string, string
|
|
82
|
+
headers?: Record<string, string>,
|
|
83
83
|
): Promise<Blob> {
|
|
84
84
|
if (!url || !headers) {
|
|
85
85
|
throw new InferenceClientInputError("URL and headers are required for text-to-video task");
|
|
@@ -87,7 +87,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
|
|
|
87
87
|
const taskId = response.task_id;
|
|
88
88
|
if (!taskId) {
|
|
89
89
|
throw new InferenceClientProviderOutputError(
|
|
90
|
-
"Received malformed response from Novita text-to-video API: no task ID found in the response"
|
|
90
|
+
"Received malformed response from Novita text-to-video API: no task ID found in the response",
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -111,7 +111,7 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
|
|
|
111
111
|
requestId: resultResponse.headers.get("x-request-id") ?? "",
|
|
112
112
|
status: resultResponse.status,
|
|
113
113
|
body: await resultResponse.text(),
|
|
114
|
-
}
|
|
114
|
+
},
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
try {
|
|
@@ -128,12 +128,12 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
|
|
|
128
128
|
status = taskResult.task.status;
|
|
129
129
|
} else {
|
|
130
130
|
throw new InferenceClientProviderOutputError(
|
|
131
|
-
"Received malformed response from Novita text-to-video API: failed to get task status"
|
|
131
|
+
"Received malformed response from Novita text-to-video API: failed to get task status",
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
} catch (error) {
|
|
135
135
|
throw new InferenceClientProviderOutputError(
|
|
136
|
-
"Received malformed response from Novita text-to-video API: failed to parse task result"
|
|
136
|
+
"Received malformed response from Novita text-to-video API: failed to parse task result",
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -159,8 +159,8 @@ export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToV
|
|
|
159
159
|
} else {
|
|
160
160
|
throw new InferenceClientProviderOutputError(
|
|
161
161
|
`Received malformed response from Novita text-to-video API: expected { videos: [{ video_url: string }] } format, got instead: ${JSON.stringify(
|
|
162
|
-
taskResult
|
|
163
|
-
)}
|
|
162
|
+
taskResult,
|
|
163
|
+
)}`,
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
166
|
}
|
package/src/providers/nscale.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class NscaleTextToImageTask extends TaskProviderHelper implements TextToI
|
|
|
42
42
|
preparePayload(params: BodyParams<TextToImageInput>): Record<string, unknown> {
|
|
43
43
|
if (params.outputType === "url") {
|
|
44
44
|
throw new InferenceClientInputError(
|
|
45
|
-
"nscale provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead."
|
|
45
|
+
"nscale provider does not support URL output. Use outputType 'blob', 'dataUrl' or 'json' instead.",
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
@@ -62,7 +62,7 @@ export class NscaleTextToImageTask extends TaskProviderHelper implements TextToI
|
|
|
62
62
|
response: NscaleCloudBase64ImageGeneration,
|
|
63
63
|
url?: string,
|
|
64
64
|
headers?: HeadersInit,
|
|
65
|
-
outputType?: OutputType
|
|
65
|
+
outputType?: OutputType,
|
|
66
66
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
67
67
|
if (
|
|
68
68
|
typeof response === "object" &&
|
|
@@ -52,7 +52,7 @@ export class OvhCloudTextGenerationTask extends BaseTextGenerationTask {
|
|
|
52
52
|
? {
|
|
53
53
|
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
|
|
54
54
|
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
|
|
55
|
-
|
|
55
|
+
}
|
|
56
56
|
: undefined),
|
|
57
57
|
prompt: params.args.inputs,
|
|
58
58
|
};
|
|
@@ -75,7 +75,7 @@ export abstract class TaskProviderHelper {
|
|
|
75
75
|
constructor(
|
|
76
76
|
readonly provider: InferenceProvider,
|
|
77
77
|
protected baseUrl: string,
|
|
78
|
-
readonly clientSideRoutingOnly: boolean = false
|
|
78
|
+
readonly clientSideRoutingOnly: boolean = false,
|
|
79
79
|
) {}
|
|
80
80
|
|
|
81
81
|
/**
|
|
@@ -86,7 +86,7 @@ export abstract class TaskProviderHelper {
|
|
|
86
86
|
response: unknown,
|
|
87
87
|
url?: string,
|
|
88
88
|
headers?: HeadersInit,
|
|
89
|
-
outputType?: OutputType
|
|
89
|
+
outputType?: OutputType,
|
|
90
90
|
): Promise<unknown>;
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -152,7 +152,7 @@ export interface TextToImageTaskHelper {
|
|
|
152
152
|
response: unknown,
|
|
153
153
|
url?: string,
|
|
154
154
|
headers?: HeadersInit,
|
|
155
|
-
outputType?: OutputType
|
|
155
|
+
outputType?: OutputType,
|
|
156
156
|
): Promise<string | Blob | Record<string, unknown>>;
|
|
157
157
|
preparePayload(params: BodyParams<TextToImageInput & BaseArgs>): Record<string, unknown>;
|
|
158
158
|
}
|
|
@@ -282,7 +282,7 @@ export interface TextToAudioTaskHelper {
|
|
|
282
282
|
export interface AudioToAudioTaskHelper {
|
|
283
283
|
getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise<AudioToAudioOutput[]>;
|
|
284
284
|
preparePayload(
|
|
285
|
-
params: BodyParams<BaseArgs & { inputs: Blob } & Record<string, unknown
|
|
285
|
+
params: BodyParams<BaseArgs & { inputs: Blob } & Record<string, unknown>>,
|
|
286
286
|
): Record<string, unknown> | BodyInit;
|
|
287
287
|
}
|
|
288
288
|
export interface AutomaticSpeechRecognitionTaskHelper {
|
|
@@ -315,14 +315,14 @@ export interface VisualQuestionAnsweringTaskHelper {
|
|
|
315
315
|
export interface TabularClassificationTaskHelper {
|
|
316
316
|
getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise<number[]>;
|
|
317
317
|
preparePayload(
|
|
318
|
-
params: BodyParams<BaseArgs & { inputs: { data: Record<string, string[]> } } & Record<string, unknown
|
|
318
|
+
params: BodyParams<BaseArgs & { inputs: { data: Record<string, string[]> } } & Record<string, unknown>>,
|
|
319
319
|
): Record<string, unknown> | BodyInit;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
export interface TabularRegressionTaskHelper {
|
|
323
323
|
getResponse(response: unknown, url?: string, headers?: HeadersInit): Promise<number[]>;
|
|
324
324
|
preparePayload(
|
|
325
|
-
params: BodyParams<BaseArgs & { inputs: { data: Record<string, string[]> } } & Record<string, unknown
|
|
325
|
+
params: BodyParams<BaseArgs & { inputs: { data: Record<string, string[]> } } & Record<string, unknown>>,
|
|
326
326
|
): Record<string, unknown> | BodyInit;
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -387,7 +387,7 @@ export class BaseTextGenerationTask extends TaskProviderHelper implements TextGe
|
|
|
387
387
|
res.length > 0 &&
|
|
388
388
|
res.every(
|
|
389
389
|
(x): x is { generated_text: string } =>
|
|
390
|
-
typeof x === "object" && !!x && "generated_text" in x && typeof x.generated_text === "string"
|
|
390
|
+
typeof x === "object" && !!x && "generated_text" in x && typeof x.generated_text === "string",
|
|
391
391
|
)
|
|
392
392
|
) {
|
|
393
393
|
return res[0];
|
|
@@ -92,7 +92,7 @@ export class ReplicateTextToImageTask extends ReplicateTask implements TextToIma
|
|
|
92
92
|
res: ReplicateOutput | Blob,
|
|
93
93
|
url?: string,
|
|
94
94
|
headers?: Record<string, string>,
|
|
95
|
-
outputType?: OutputType
|
|
95
|
+
outputType?: OutputType,
|
|
96
96
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
97
97
|
void url;
|
|
98
98
|
void headers;
|
|
@@ -236,18 +236,23 @@ export class ReplicateAutomaticSpeechRecognitionTask
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
throw new InferenceClientProviderOutputError(
|
|
239
|
-
"Received malformed response from Replicate automatic-speech-recognition API"
|
|
239
|
+
"Received malformed response from Replicate automatic-speech-recognition API",
|
|
240
240
|
);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
export class ReplicateImageToImageTask extends ReplicateTask implements ImageToImageTaskHelper {
|
|
245
245
|
override preparePayload(params: BodyParams<ImageToImageArgs>): Record<string, unknown> {
|
|
246
|
+
const imageInput = params.args.inputs; // This will be processed in preparePayloadAsync
|
|
246
247
|
return {
|
|
247
248
|
input: {
|
|
248
249
|
...omit(params.args, ["inputs", "parameters"]),
|
|
249
250
|
...params.args.parameters,
|
|
250
|
-
|
|
251
|
+
// Different Replicate models expect the image in different keys
|
|
252
|
+
image: imageInput,
|
|
253
|
+
images: [imageInput],
|
|
254
|
+
input_image: imageInput,
|
|
255
|
+
input_images: [imageInput],
|
|
251
256
|
lora_weights:
|
|
252
257
|
params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath
|
|
253
258
|
? `https://huggingface.co/${params.mapping.hfModelId}`
|
|
@@ -54,7 +54,7 @@ export class SambanovaFeatureExtractionTask extends TaskProviderHelper implement
|
|
|
54
54
|
return response.data.map((item) => item.embedding);
|
|
55
55
|
}
|
|
56
56
|
throw new InferenceClientProviderOutputError(
|
|
57
|
-
"Received malformed response from Sambanova feature-extraction (embeddings) API"
|
|
57
|
+
"Received malformed response from Sambanova feature-extraction (embeddings) API",
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -119,7 +119,7 @@ export class TogetherTextToImageTask extends TaskProviderHelper implements TextT
|
|
|
119
119
|
response: TogetherImageGeneration,
|
|
120
120
|
url?: string,
|
|
121
121
|
headers?: HeadersInit,
|
|
122
|
-
outputType?: OutputType
|
|
122
|
+
outputType?: OutputType,
|
|
123
123
|
): Promise<string | Blob | Record<string, unknown>> {
|
|
124
124
|
if (
|
|
125
125
|
typeof response === "object" &&
|