@huggingface/inference 3.10.0 → 3.12.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/dist/index.cjs +713 -643
- package/dist/index.js +712 -643
- package/dist/src/InferenceClient.d.ts +16 -17
- package/dist/src/InferenceClient.d.ts.map +1 -1
- package/dist/src/lib/getInferenceProviderMapping.d.ts +5 -1
- package/dist/src/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/src/providers/providerHelper.d.ts +1 -1
- package/dist/src/providers/providerHelper.d.ts.map +1 -1
- package/dist/src/tasks/audio/audioClassification.d.ts.map +1 -1
- package/dist/src/tasks/audio/audioToAudio.d.ts.map +1 -1
- package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/src/tasks/audio/textToSpeech.d.ts.map +1 -1
- package/dist/src/tasks/custom/request.d.ts.map +1 -1
- package/dist/src/tasks/custom/streamingRequest.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageClassification.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageSegmentation.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageToImage.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageToText.d.ts.map +1 -1
- package/dist/src/tasks/cv/objectDetection.d.ts.map +1 -1
- package/dist/src/tasks/cv/textToImage.d.ts.map +1 -1
- package/dist/src/tasks/cv/textToVideo.d.ts.map +1 -1
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts.map +1 -1
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/chatCompletion.d.ts.map +1 -1
- package/dist/src/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
- package/dist/src/tasks/nlp/featureExtraction.d.ts.map +1 -1
- package/dist/src/tasks/nlp/fillMask.d.ts.map +1 -1
- package/dist/src/tasks/nlp/questionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/sentenceSimilarity.d.ts.map +1 -1
- package/dist/src/tasks/nlp/summarization.d.ts.map +1 -1
- package/dist/src/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/textClassification.d.ts.map +1 -1
- package/dist/src/tasks/nlp/textGeneration.d.ts.map +1 -1
- package/dist/src/tasks/nlp/textGenerationStream.d.ts.map +1 -1
- package/dist/src/tasks/nlp/tokenClassification.d.ts.map +1 -1
- package/dist/src/tasks/nlp/translation.d.ts.map +1 -1
- package/dist/src/tasks/nlp/zeroShotClassification.d.ts.map +1 -1
- package/dist/src/tasks/tabular/tabularClassification.d.ts.map +1 -1
- package/dist/src/tasks/tabular/tabularRegression.d.ts.map +1 -1
- package/dist/src/types.d.ts +6 -4
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/typedEntries.d.ts +4 -0
- package/dist/src/utils/typedEntries.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/InferenceClient.ts +32 -43
- package/src/lib/getInferenceProviderMapping.ts +68 -19
- package/src/lib/makeRequestOptions.ts +4 -3
- package/src/providers/hf-inference.ts +1 -1
- package/src/providers/providerHelper.ts +1 -1
- package/src/snippets/getInferenceSnippets.ts +1 -1
- package/src/tasks/audio/audioClassification.ts +3 -1
- package/src/tasks/audio/audioToAudio.ts +4 -1
- package/src/tasks/audio/automaticSpeechRecognition.ts +3 -1
- package/src/tasks/audio/textToSpeech.ts +2 -1
- package/src/tasks/custom/request.ts +3 -1
- package/src/tasks/custom/streamingRequest.ts +3 -1
- package/src/tasks/cv/imageClassification.ts +3 -1
- package/src/tasks/cv/imageSegmentation.ts +3 -1
- package/src/tasks/cv/imageToImage.ts +3 -1
- package/src/tasks/cv/imageToText.ts +3 -1
- package/src/tasks/cv/objectDetection.ts +3 -1
- package/src/tasks/cv/textToImage.ts +2 -1
- package/src/tasks/cv/textToVideo.ts +2 -1
- package/src/tasks/cv/zeroShotImageClassification.ts +3 -1
- package/src/tasks/multimodal/documentQuestionAnswering.ts +3 -1
- package/src/tasks/multimodal/visualQuestionAnswering.ts +3 -1
- package/src/tasks/nlp/chatCompletion.ts +3 -1
- package/src/tasks/nlp/chatCompletionStream.ts +3 -1
- package/src/tasks/nlp/featureExtraction.ts +3 -1
- package/src/tasks/nlp/fillMask.ts +3 -1
- package/src/tasks/nlp/questionAnswering.ts +4 -1
- package/src/tasks/nlp/sentenceSimilarity.ts +3 -1
- package/src/tasks/nlp/summarization.ts +3 -1
- package/src/tasks/nlp/tableQuestionAnswering.ts +3 -1
- package/src/tasks/nlp/textClassification.ts +3 -1
- package/src/tasks/nlp/textGeneration.ts +3 -1
- package/src/tasks/nlp/textGenerationStream.ts +3 -1
- package/src/tasks/nlp/tokenClassification.ts +3 -1
- package/src/tasks/nlp/translation.ts +3 -1
- package/src/tasks/nlp/zeroShotClassification.ts +3 -1
- package/src/tasks/tabular/tabularClassification.ts +3 -1
- package/src/tasks/tabular/tabularRegression.ts +3 -1
- package/src/types.ts +8 -4
- package/src/utils/typedEntries.ts +5 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TextGenerationInput } from "@huggingface/tasks";
|
|
2
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
2
3
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
3
4
|
import type { BaseArgs, Options } from "../../types";
|
|
4
5
|
import { innerStreamingRequest } from "../../utils/request";
|
|
@@ -90,7 +91,8 @@ export async function* textGenerationStream(
|
|
|
90
91
|
args: BaseArgs & TextGenerationInput,
|
|
91
92
|
options?: Options
|
|
92
93
|
): AsyncGenerator<TextGenerationStreamOutput> {
|
|
93
|
-
const
|
|
94
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
95
|
+
const providerHelper = getProviderHelper(provider, "text-generation");
|
|
94
96
|
yield* innerStreamingRequest<TextGenerationStreamOutput>(args, providerHelper, {
|
|
95
97
|
...options,
|
|
96
98
|
task: "text-generation",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TokenClassificationInput, TokenClassificationOutput } from "@huggingface/tasks";
|
|
2
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
2
3
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
3
4
|
import type { BaseArgs, Options } from "../../types";
|
|
4
5
|
import { innerRequest } from "../../utils/request";
|
|
@@ -12,7 +13,8 @@ export async function tokenClassification(
|
|
|
12
13
|
args: TokenClassificationArgs,
|
|
13
14
|
options?: Options
|
|
14
15
|
): Promise<TokenClassificationOutput> {
|
|
15
|
-
const
|
|
16
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
17
|
+
const providerHelper = getProviderHelper(provider, "token-classification");
|
|
16
18
|
const { data: res } = await innerRequest<TokenClassificationOutput[number] | TokenClassificationOutput>(
|
|
17
19
|
args,
|
|
18
20
|
providerHelper,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TranslationInput, TranslationOutput } from "@huggingface/tasks";
|
|
2
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
2
3
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
3
4
|
import type { BaseArgs, Options } from "../../types";
|
|
4
5
|
import { innerRequest } from "../../utils/request";
|
|
@@ -8,7 +9,8 @@ export type TranslationArgs = BaseArgs & TranslationInput;
|
|
|
8
9
|
* This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.
|
|
9
10
|
*/
|
|
10
11
|
export async function translation(args: TranslationArgs, options?: Options): Promise<TranslationOutput> {
|
|
11
|
-
const
|
|
12
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
13
|
+
const providerHelper = getProviderHelper(provider, "translation");
|
|
12
14
|
const { data: res } = await innerRequest<TranslationOutput>(args, providerHelper, {
|
|
13
15
|
...options,
|
|
14
16
|
task: "translation",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ZeroShotClassificationInput, ZeroShotClassificationOutput } from "@huggingface/tasks";
|
|
2
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
2
3
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
3
4
|
import type { BaseArgs, Options } from "../../types";
|
|
4
5
|
import { innerRequest } from "../../utils/request";
|
|
@@ -12,7 +13,8 @@ export async function zeroShotClassification(
|
|
|
12
13
|
args: ZeroShotClassificationArgs,
|
|
13
14
|
options?: Options
|
|
14
15
|
): Promise<ZeroShotClassificationOutput> {
|
|
15
|
-
const
|
|
16
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
17
|
+
const providerHelper = getProviderHelper(provider, "zero-shot-classification");
|
|
16
18
|
const { data: res } = await innerRequest<ZeroShotClassificationOutput[number] | ZeroShotClassificationOutput>(
|
|
17
19
|
args,
|
|
18
20
|
providerHelper,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
1
2
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
2
3
|
import type { BaseArgs, Options } from "../../types";
|
|
3
4
|
import { innerRequest } from "../../utils/request";
|
|
@@ -25,7 +26,8 @@ export async function tabularClassification(
|
|
|
25
26
|
args: TabularClassificationArgs,
|
|
26
27
|
options?: Options
|
|
27
28
|
): Promise<TabularClassificationOutput> {
|
|
28
|
-
const
|
|
29
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
30
|
+
const providerHelper = getProviderHelper(provider, "tabular-classification");
|
|
29
31
|
const { data: res } = await innerRequest<TabularClassificationOutput>(args, providerHelper, {
|
|
30
32
|
...options,
|
|
31
33
|
task: "tabular-classification",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveProvider } from "../../lib/getInferenceProviderMapping";
|
|
1
2
|
import { getProviderHelper } from "../../lib/getProviderHelper";
|
|
2
3
|
import type { BaseArgs, Options } from "../../types";
|
|
3
4
|
import { innerRequest } from "../../utils/request";
|
|
@@ -25,7 +26,8 @@ export async function tabularRegression(
|
|
|
25
26
|
args: TabularRegressionArgs,
|
|
26
27
|
options?: Options
|
|
27
28
|
): Promise<TabularRegressionOutput> {
|
|
28
|
-
const
|
|
29
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
30
|
+
const providerHelper = getProviderHelper(provider, "tabular-regression");
|
|
29
31
|
const { data: res } = await innerRequest<TabularRegressionOutput>(args, providerHelper, {
|
|
30
32
|
...options,
|
|
31
33
|
task: "tabular-regression",
|
package/src/types.ts
CHANGED
|
@@ -57,8 +57,12 @@ export const INFERENCE_PROVIDERS = [
|
|
|
57
57
|
"together",
|
|
58
58
|
] as const;
|
|
59
59
|
|
|
60
|
+
export const PROVIDERS_OR_POLICIES = [...INFERENCE_PROVIDERS, "auto"] as const;
|
|
61
|
+
|
|
60
62
|
export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
|
|
61
63
|
|
|
64
|
+
export type InferenceProviderOrPolicy = (typeof PROVIDERS_OR_POLICIES)[number];
|
|
65
|
+
|
|
62
66
|
export interface BaseArgs {
|
|
63
67
|
/**
|
|
64
68
|
* The access token to use. Without it, you'll get rate-limited quickly.
|
|
@@ -80,18 +84,18 @@ export interface BaseArgs {
|
|
|
80
84
|
model?: ModelId;
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
|
-
* The URL of the endpoint to use.
|
|
87
|
+
* The URL of the endpoint to use.
|
|
84
88
|
*
|
|
85
|
-
* If specified, will
|
|
89
|
+
* If not specified, will call the default router.huggingface.co Inference Providers endpoint.
|
|
86
90
|
*/
|
|
87
91
|
endpointUrl?: string;
|
|
88
92
|
|
|
89
93
|
/**
|
|
90
94
|
* Set an Inference provider to run this model on.
|
|
91
95
|
*
|
|
92
|
-
* Defaults to the first
|
|
96
|
+
* Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
|
|
93
97
|
*/
|
|
94
|
-
provider?:
|
|
98
|
+
provider?: InferenceProviderOrPolicy;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
export type RequestArgs = BaseArgs &
|