Skip to content

Commit 68fda16

Browse files
committed
fixes
1 parent 77bd605 commit 68fda16

30 files changed

+148
-200
lines changed

packages/inference/src/tasks/audio/audioClassification.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ export async function audioClassification(
1616
options?: Options
1717
): Promise<AudioClassificationOutput> {
1818
const payload = preparePayload(args);
19-
const res = (
20-
await innerRequest<AudioClassificationOutput>(payload, {
21-
...options,
22-
task: "audio-classification",
23-
})
24-
).data;
19+
const { data: res } = await innerRequest<AudioClassificationOutput>(payload, {
20+
...options,
21+
task: "audio-classification",
22+
});
2523
const isValidOutput =
2624
Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
2725
if (!isValidOutput) {

packages/inference/src/tasks/audio/audioToAudio.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ export interface AudioToAudioOutput {
3737
*/
3838
export async function audioToAudio(args: AudioToAudioArgs, options?: Options): Promise<AudioToAudioOutput[]> {
3939
const payload = preparePayload(args);
40-
const res = (
41-
await innerRequest<AudioToAudioOutput>(payload, {
42-
...options,
43-
task: "audio-to-audio",
44-
})
45-
).data;
40+
const { data: res } = await innerRequest<AudioToAudioOutput>(payload, {
41+
...options,
42+
task: "audio-to-audio",
43+
});
4644

4745
return validateOutput(res);
4846
}

packages/inference/src/tasks/audio/automaticSpeechRecognition.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ export async function automaticSpeechRecognition(
1717
options?: Options
1818
): Promise<AutomaticSpeechRecognitionOutput> {
1919
const payload = await buildPayload(args);
20-
const res = (
21-
await innerRequest<AutomaticSpeechRecognitionOutput>(payload, {
22-
...options,
23-
task: "automatic-speech-recognition",
24-
})
25-
).data;
20+
const { data: res } = await innerRequest<AutomaticSpeechRecognitionOutput>(payload, {
21+
...options,
22+
task: "automatic-speech-recognition",
23+
});
2624
const isValidOutput = typeof res?.text === "string";
2725
if (!isValidOutput) {
2826
throw new InferenceOutputError("Expected {text: string}");

packages/inference/src/tasks/audio/textToSpeech.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ export async function textToSpeech(args: TextToSpeechArgs, options?: Options): P
2222
text: args.inputs,
2323
}
2424
: args;
25-
const res = (
26-
await innerRequest<Blob | OutputUrlTextToSpeechGeneration>(payload, {
27-
...options,
28-
task: "text-to-speech",
29-
})
30-
).data;
25+
const { data: res } = await innerRequest<Blob | OutputUrlTextToSpeechGeneration>(payload, {
26+
...options,
27+
task: "text-to-speech",
28+
});
3129
if (res instanceof Blob) {
3230
return res;
3331
}

packages/inference/src/tasks/custom/request.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export async function request<T>(
1414
chatCompletion?: boolean;
1515
}
1616
): Promise<T> {
17+
console.warn(
18+
"The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead."
19+
);
1720
const result = await innerRequest<T>(args, options);
1821
return result.data;
1922
}

packages/inference/src/tasks/custom/streamingRequest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ export async function* streamingRequest<T>(
1313
chatCompletion?: boolean;
1414
}
1515
): AsyncGenerator<T> {
16+
console.warn(
17+
"The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead."
18+
);
1619
yield* innerStreamingRequest(args, options);
1720
}

packages/inference/src/tasks/cv/imageClassification.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ export async function imageClassification(
1515
options?: Options
1616
): Promise<ImageClassificationOutput> {
1717
const payload = preparePayload(args);
18-
const res = (
19-
await innerRequest<ImageClassificationOutput>(payload, {
20-
...options,
21-
task: "image-classification",
22-
})
23-
).data;
18+
const { data: res } = await innerRequest<ImageClassificationOutput>(payload, {
19+
...options,
20+
task: "image-classification",
21+
});
2422
const isValidOutput =
2523
Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");
2624
if (!isValidOutput) {

packages/inference/src/tasks/cv/imageSegmentation.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ export async function imageSegmentation(
1515
options?: Options
1616
): Promise<ImageSegmentationOutput> {
1717
const payload = preparePayload(args);
18-
const res = (
19-
await innerRequest<ImageSegmentationOutput>(payload, {
20-
...options,
21-
task: "image-segmentation",
22-
})
23-
).data;
18+
const { data: res } = await innerRequest<ImageSegmentationOutput>(payload, {
19+
...options,
20+
task: "image-segmentation",
21+
});
2422
const isValidOutput =
2523
Array.isArray(res) &&
2624
res.every((x) => typeof x.label === "string" && typeof x.mask === "string" && typeof x.score === "number");

packages/inference/src/tasks/cv/imageToImage.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ export async function imageToImage(args: ImageToImageArgs, options?: Options): P
2626
),
2727
};
2828
}
29-
const res = (
30-
await innerRequest<Blob>(reqArgs, {
31-
...options,
32-
task: "image-to-image",
33-
})
34-
).data;
29+
const { data: res } = await innerRequest<Blob>(reqArgs, {
30+
...options,
31+
task: "image-to-image",
32+
});
3533
const isValidOutput = res && res instanceof Blob;
3634
if (!isValidOutput) {
3735
throw new InferenceOutputError("Expected Blob");

packages/inference/src/tasks/cv/imageToText.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ export type ImageToTextArgs = BaseArgs & (ImageToTextInput | LegacyImageInput);
1111
*/
1212
export async function imageToText(args: ImageToTextArgs, options?: Options): Promise<ImageToTextOutput> {
1313
const payload = preparePayload(args);
14-
const res = (
15-
await innerRequest<[ImageToTextOutput]>(payload, {
16-
...options,
17-
task: "image-to-text",
18-
})
19-
).data?.[0];
14+
const { data: res } = await innerRequest<[ImageToTextOutput]>(payload, {
15+
...options,
16+
task: "image-to-text",
17+
});
2018

21-
if (typeof res?.generated_text !== "string") {
19+
if (typeof res?.[0]?.generated_text !== "string") {
2220
throw new InferenceOutputError("Expected {generated_text: string}");
2321
}
2422

25-
return res;
23+
return res?.[0];
2624
}

0 commit comments

Comments
 (0)