@huggingface/inference 2.6.7 → 2.7.1
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 +126 -27
- package/dist/index.cjs +92 -24
- package/dist/index.js +90 -24
- package/dist/src/HfInference.d.ts +28 -0
- package/dist/src/HfInference.d.ts.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/lib/InferenceOutputError.d.ts +4 -0
- package/dist/src/lib/InferenceOutputError.d.ts.map +1 -0
- package/dist/src/lib/getDefaultTask.d.ts +12 -0
- package/dist/src/lib/getDefaultTask.d.ts.map +1 -0
- package/dist/src/lib/isUrl.d.ts +2 -0
- package/dist/src/lib/isUrl.d.ts.map +1 -0
- package/dist/src/lib/makeRequestOptions.d.ts +18 -0
- package/dist/src/lib/makeRequestOptions.d.ts.map +1 -0
- package/dist/src/tasks/audio/audioClassification.d.ts +24 -0
- package/dist/src/tasks/audio/audioClassification.d.ts.map +1 -0
- package/dist/src/tasks/audio/audioToAudio.d.ts +28 -0
- package/dist/src/tasks/audio/audioToAudio.d.ts.map +1 -0
- package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts +19 -0
- package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -0
- package/dist/src/tasks/audio/textToSpeech.d.ts +14 -0
- package/dist/src/tasks/audio/textToSpeech.d.ts.map +1 -0
- package/dist/src/tasks/custom/request.d.ts +13 -0
- package/dist/src/tasks/custom/request.d.ts.map +1 -0
- package/dist/src/tasks/custom/streamingRequest.d.ts +13 -0
- package/dist/src/tasks/custom/streamingRequest.d.ts.map +1 -0
- package/dist/src/tasks/cv/imageClassification.d.ts +24 -0
- package/dist/src/tasks/cv/imageClassification.d.ts.map +1 -0
- package/dist/src/tasks/cv/imageSegmentation.d.ts +28 -0
- package/dist/src/tasks/cv/imageSegmentation.d.ts.map +1 -0
- package/dist/src/tasks/cv/imageToImage.d.ts +55 -0
- package/dist/src/tasks/cv/imageToImage.d.ts.map +1 -0
- package/dist/src/tasks/cv/imageToText.d.ts +18 -0
- package/dist/src/tasks/cv/imageToText.d.ts.map +1 -0
- package/dist/src/tasks/cv/objectDetection.d.ts +33 -0
- package/dist/src/tasks/cv/objectDetection.d.ts.map +1 -0
- package/dist/src/tasks/cv/textToImage.d.ts +36 -0
- package/dist/src/tasks/cv/textToImage.d.ts.map +1 -0
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts +26 -0
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts.map +1 -0
- package/dist/src/tasks/index.d.ts +32 -0
- package/dist/src/tasks/index.d.ts.map +1 -0
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts +35 -0
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -0
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts +27 -0
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -0
- package/dist/src/tasks/nlp/chatCompletion.d.ts +7 -0
- package/dist/src/tasks/nlp/chatCompletion.d.ts.map +1 -0
- package/dist/src/tasks/nlp/chatCompletionStream.d.ts +7 -0
- package/dist/src/tasks/nlp/chatCompletionStream.d.ts.map +1 -0
- package/dist/src/tasks/nlp/featureExtraction.d.ts +19 -0
- package/dist/src/tasks/nlp/featureExtraction.d.ts.map +1 -0
- package/dist/src/tasks/nlp/fillMask.d.ts +27 -0
- package/dist/src/tasks/nlp/fillMask.d.ts.map +1 -0
- package/dist/src/tasks/nlp/questionAnswering.d.ts +30 -0
- package/dist/src/tasks/nlp/questionAnswering.d.ts.map +1 -0
- package/dist/src/tasks/nlp/sentenceSimilarity.d.ts +19 -0
- package/dist/src/tasks/nlp/sentenceSimilarity.d.ts.map +1 -0
- package/dist/src/tasks/nlp/summarization.d.ts +48 -0
- package/dist/src/tasks/nlp/summarization.d.ts.map +1 -0
- package/dist/src/tasks/nlp/tableQuestionAnswering.d.ts +36 -0
- package/dist/src/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -0
- package/dist/src/tasks/nlp/textClassification.d.ts +22 -0
- package/dist/src/tasks/nlp/textClassification.d.ts.map +1 -0
- package/dist/src/tasks/nlp/textGeneration.d.ts +8 -0
- package/dist/src/tasks/nlp/textGeneration.d.ts.map +1 -0
- package/dist/src/tasks/nlp/textGenerationStream.d.ts +81 -0
- package/dist/src/tasks/nlp/textGenerationStream.d.ts.map +1 -0
- package/dist/src/tasks/nlp/tokenClassification.d.ts +51 -0
- package/dist/src/tasks/nlp/tokenClassification.d.ts.map +1 -0
- package/dist/src/tasks/nlp/translation.d.ts +19 -0
- package/dist/src/tasks/nlp/translation.d.ts.map +1 -0
- package/dist/src/tasks/nlp/zeroShotClassification.d.ts +28 -0
- package/dist/src/tasks/nlp/zeroShotClassification.d.ts.map +1 -0
- package/dist/src/tasks/tabular/tabularClassification.d.ts +20 -0
- package/dist/src/tasks/tabular/tabularClassification.d.ts.map +1 -0
- package/dist/src/tasks/tabular/tabularRegression.d.ts +20 -0
- package/dist/src/tasks/tabular/tabularRegression.d.ts.map +1 -0
- package/dist/src/types.d.ts +69 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/base64FromBytes.d.ts +2 -0
- package/dist/src/utils/base64FromBytes.d.ts.map +1 -0
- package/dist/src/utils/distributive-omit.d.ts +9 -0
- package/dist/src/utils/distributive-omit.d.ts.map +1 -0
- package/dist/src/utils/isBackend.d.ts +2 -0
- package/dist/src/utils/isBackend.d.ts.map +1 -0
- package/dist/src/utils/isFrontend.d.ts +2 -0
- package/dist/src/utils/isFrontend.d.ts.map +1 -0
- package/dist/src/utils/omit.d.ts +5 -0
- package/dist/src/utils/omit.d.ts.map +1 -0
- package/dist/src/utils/pick.d.ts +5 -0
- package/dist/src/utils/pick.d.ts.map +1 -0
- package/dist/src/utils/toArray.d.ts +2 -0
- package/dist/src/utils/toArray.d.ts.map +1 -0
- package/dist/src/utils/typedInclude.d.ts +2 -0
- package/dist/src/utils/typedInclude.d.ts.map +1 -0
- package/dist/src/vendor/fetch-event-source/parse.d.ts +69 -0
- package/dist/src/vendor/fetch-event-source/parse.d.ts.map +1 -0
- package/dist/src/vendor/fetch-event-source/parse.spec.d.ts +2 -0
- package/dist/src/vendor/fetch-event-source/parse.spec.d.ts.map +1 -0
- package/dist/test/HfInference.spec.d.ts +2 -0
- package/dist/test/HfInference.spec.d.ts.map +1 -0
- package/dist/test/expect-closeto.d.ts +2 -0
- package/dist/test/expect-closeto.d.ts.map +1 -0
- package/dist/test/test-files.d.ts +2 -0
- package/dist/test/test-files.d.ts.map +1 -0
- package/dist/test/vcr.d.ts +2 -0
- package/dist/test/vcr.d.ts.map +1 -0
- package/package.json +9 -7
- package/src/HfInference.ts +4 -4
- package/src/lib/makeRequestOptions.ts +17 -7
- package/src/tasks/custom/request.ts +5 -0
- package/src/tasks/custom/streamingRequest.ts +8 -0
- package/src/tasks/cv/imageToImage.ts +1 -1
- package/src/tasks/cv/zeroShotImageClassification.ts +1 -1
- package/src/tasks/index.ts +2 -0
- package/src/tasks/multimodal/documentQuestionAnswering.ts +1 -1
- package/src/tasks/multimodal/visualQuestionAnswering.ts +1 -1
- package/src/tasks/nlp/chatCompletion.ts +32 -0
- package/src/tasks/nlp/chatCompletionStream.ts +17 -0
- package/src/tasks/nlp/textGeneration.ts +9 -206
- package/src/tasks/nlp/textGenerationStream.ts +2 -1
- package/src/types.ts +14 -3
- package/src/utils/base64FromBytes.ts +11 -0
- package/src/utils/{distributive-omit.d.ts → distributive-omit.ts} +0 -2
- package/src/utils/isBackend.ts +6 -0
- package/src/utils/isFrontend.ts +3 -0
- package/dist/index.d.ts +0 -1536
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { TextGenerationInput } from "@huggingface/tasks";
|
|
1
2
|
import type { BaseArgs, Options } from "../../types";
|
|
2
3
|
import { streamingRequest } from "../custom/streamingRequest";
|
|
3
|
-
import type { TextGenerationInput } from "./textGeneration";
|
|
4
4
|
|
|
5
5
|
export interface TextGenerationStreamToken {
|
|
6
6
|
/** Token ID from the model tokenizer */
|
|
@@ -67,6 +67,7 @@ export interface TextGenerationStreamDetails {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface TextGenerationStreamOutput {
|
|
70
|
+
index?: number;
|
|
70
71
|
/** Generated token, one at a time */
|
|
71
72
|
token: TextGenerationStreamToken;
|
|
72
73
|
/**
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PipelineType } from "@huggingface/tasks";
|
|
2
|
+
import type { ChatCompletionInput } from "@huggingface/tasks";
|
|
2
3
|
|
|
3
4
|
export interface Options {
|
|
4
5
|
/**
|
|
@@ -32,7 +33,7 @@ export interface Options {
|
|
|
32
33
|
signal?: AbortSignal;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
|
-
* Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all
|
|
36
|
+
* (Default: "same-origin"). String | Boolean. Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
|
|
36
37
|
*/
|
|
37
38
|
includeCredentials?: string | boolean;
|
|
38
39
|
}
|
|
@@ -47,15 +48,25 @@ export interface BaseArgs {
|
|
|
47
48
|
*/
|
|
48
49
|
accessToken?: string;
|
|
49
50
|
/**
|
|
50
|
-
* The model to use.
|
|
51
|
+
* The model to use.
|
|
51
52
|
*
|
|
52
53
|
* If not specified, will call huggingface.co/api/tasks to get the default model for the task.
|
|
54
|
+
*
|
|
55
|
+
* /!\ Legacy behavior allows this to be an URL, but this is deprecated and will be removed in the future.
|
|
56
|
+
* Use the `endpointUrl` parameter instead.
|
|
53
57
|
*/
|
|
54
58
|
model?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The URL of the endpoint to use. If not specified, will call huggingface.co/api/tasks to get the default endpoint for the task.
|
|
62
|
+
*
|
|
63
|
+
* If specified, will use this URL instead of the default one.
|
|
64
|
+
*/
|
|
65
|
+
endpointUrl?: string;
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
export type RequestArgs = BaseArgs &
|
|
58
|
-
({ data: Blob | ArrayBuffer } | { inputs: unknown }) & {
|
|
69
|
+
({ data: Blob | ArrayBuffer } | { inputs: unknown } | ChatCompletionInput) & {
|
|
59
70
|
parameters?: Record<string, unknown>;
|
|
60
71
|
accessToken?: string;
|
|
61
72
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function base64FromBytes(arr: Uint8Array): string {
|
|
2
|
+
if (globalThis.Buffer) {
|
|
3
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
4
|
+
} else {
|
|
5
|
+
const bin: string[] = [];
|
|
6
|
+
arr.forEach((byte) => {
|
|
7
|
+
bin.push(String.fromCharCode(byte));
|
|
8
|
+
});
|
|
9
|
+
return globalThis.btoa(bin.join(""));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* This allows omitting keys from objects inside unions, without merging the individual components of the union.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
type Keys<T> = keyof T;
|
|
8
|
-
type DistributiveKeys<T> = T extends unknown ? Keys<T> : never;
|
|
9
7
|
type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
|
|
10
8
|
|
|
11
9
|
export type DistributiveOmit<T, K> = T extends unknown
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2
|
+
|
|
3
|
+
const isWebWorker =
|
|
4
|
+
typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
|
|
5
|
+
|
|
6
|
+
export const isBackend = !isBrowser && !isWebWorker;
|