@huggingface/inference 2.6.2 → 2.6.4
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 +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -5
- package/dist/index.mjs +6 -5
- package/package.json +1 -1
- package/src/lib/getDefaultTask.ts +10 -2
- package/src/lib/makeRequestOptions.ts +1 -0
- package/src/tasks/nlp/featureExtraction.ts +1 -1
- package/src/tasks/nlp/sentenceSimilarity.ts +1 -1
- package/src/tasks/nlp/textGeneration.ts +4 -0
- package/src/types.ts +4 -0
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface Options {
|
|
|
24
24
|
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
|
|
25
25
|
*/
|
|
26
26
|
fetch?: typeof fetch;
|
|
27
|
+
/**
|
|
28
|
+
* Abort Controller signal to use for request interruption.
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* (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.
|
|
@@ -786,6 +790,10 @@ export type TextGenerationArgs = BaseArgs & {
|
|
|
786
790
|
* (Default: None). Integer. The maximum number of tokens from the input.
|
|
787
791
|
*/
|
|
788
792
|
truncate?: number;
|
|
793
|
+
/**
|
|
794
|
+
* (Default: []) List of strings. The model will stop generating text when one of the strings in the list is generated.
|
|
795
|
+
* **/
|
|
796
|
+
stop_sequences?: string[];
|
|
789
797
|
};
|
|
790
798
|
};
|
|
791
799
|
export interface TextGenerationOutput {
|
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ var taskCache = /* @__PURE__ */ new Map();
|
|
|
102
102
|
var CACHE_DURATION = 10 * 60 * 1e3;
|
|
103
103
|
var MAX_CACHE_ITEMS = 1e3;
|
|
104
104
|
var HF_HUB_URL = "https://huggingface.co";
|
|
105
|
-
async function getDefaultTask(model, accessToken) {
|
|
105
|
+
async function getDefaultTask(model, accessToken, options) {
|
|
106
106
|
if (isUrl(model)) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
@@ -113,7 +113,7 @@ async function getDefaultTask(model, accessToken) {
|
|
|
113
113
|
cachedTask = void 0;
|
|
114
114
|
}
|
|
115
115
|
if (cachedTask === void 0) {
|
|
116
|
-
const modelTask = await fetch(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
116
|
+
const modelTask = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
117
117
|
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
|
|
118
118
|
}).then((resp) => resp.json()).then((json) => json.pipeline_tag).catch(() => null);
|
|
119
119
|
if (!modelTask) {
|
|
@@ -192,7 +192,8 @@ async function makeRequestOptions(args, options) {
|
|
|
192
192
|
...otherArgs,
|
|
193
193
|
options: options && otherOptions
|
|
194
194
|
}),
|
|
195
|
-
credentials
|
|
195
|
+
credentials,
|
|
196
|
+
signal: options?.signal
|
|
196
197
|
};
|
|
197
198
|
return { url, info };
|
|
198
199
|
}
|
|
@@ -598,7 +599,7 @@ async function conversational(args, options) {
|
|
|
598
599
|
|
|
599
600
|
// src/tasks/nlp/featureExtraction.ts
|
|
600
601
|
async function featureExtraction(args, options) {
|
|
601
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
602
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
602
603
|
const res = await request(args, {
|
|
603
604
|
...options,
|
|
604
605
|
taskHint: "feature-extraction",
|
|
@@ -653,7 +654,7 @@ async function questionAnswering(args, options) {
|
|
|
653
654
|
|
|
654
655
|
// src/tasks/nlp/sentenceSimilarity.ts
|
|
655
656
|
async function sentenceSimilarity(args, options) {
|
|
656
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
657
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
657
658
|
const res = await request(args, {
|
|
658
659
|
...options,
|
|
659
660
|
taskHint: "sentence-similarity",
|
package/dist/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ var taskCache = /* @__PURE__ */ new Map();
|
|
|
50
50
|
var CACHE_DURATION = 10 * 60 * 1e3;
|
|
51
51
|
var MAX_CACHE_ITEMS = 1e3;
|
|
52
52
|
var HF_HUB_URL = "https://huggingface.co";
|
|
53
|
-
async function getDefaultTask(model, accessToken) {
|
|
53
|
+
async function getDefaultTask(model, accessToken, options) {
|
|
54
54
|
if (isUrl(model)) {
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
@@ -61,7 +61,7 @@ async function getDefaultTask(model, accessToken) {
|
|
|
61
61
|
cachedTask = void 0;
|
|
62
62
|
}
|
|
63
63
|
if (cachedTask === void 0) {
|
|
64
|
-
const modelTask = await fetch(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
64
|
+
const modelTask = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
65
65
|
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}
|
|
66
66
|
}).then((resp) => resp.json()).then((json) => json.pipeline_tag).catch(() => null);
|
|
67
67
|
if (!modelTask) {
|
|
@@ -140,7 +140,8 @@ async function makeRequestOptions(args, options) {
|
|
|
140
140
|
...otherArgs,
|
|
141
141
|
options: options && otherOptions
|
|
142
142
|
}),
|
|
143
|
-
credentials
|
|
143
|
+
credentials,
|
|
144
|
+
signal: options?.signal
|
|
144
145
|
};
|
|
145
146
|
return { url, info };
|
|
146
147
|
}
|
|
@@ -546,7 +547,7 @@ async function conversational(args, options) {
|
|
|
546
547
|
|
|
547
548
|
// src/tasks/nlp/featureExtraction.ts
|
|
548
549
|
async function featureExtraction(args, options) {
|
|
549
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
550
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
550
551
|
const res = await request(args, {
|
|
551
552
|
...options,
|
|
552
553
|
taskHint: "feature-extraction",
|
|
@@ -601,7 +602,7 @@ async function questionAnswering(args, options) {
|
|
|
601
602
|
|
|
602
603
|
// src/tasks/nlp/sentenceSimilarity.ts
|
|
603
604
|
async function sentenceSimilarity(args, options) {
|
|
604
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
605
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
605
606
|
const res = await request(args, {
|
|
606
607
|
...options,
|
|
607
608
|
taskHint: "sentence-similarity",
|
package/package.json
CHANGED
|
@@ -10,13 +10,21 @@ const CACHE_DURATION = 10 * 60 * 1000;
|
|
|
10
10
|
const MAX_CACHE_ITEMS = 1000;
|
|
11
11
|
export const HF_HUB_URL = "https://huggingface.co";
|
|
12
12
|
|
|
13
|
+
export interface DefaultTaskOptions {
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* Get the default task. Use a LRU cache of 1000 items with 10 minutes expiration
|
|
15
19
|
* to avoid making too many calls to the HF hub.
|
|
16
20
|
*
|
|
17
21
|
* @returns The default task for the model, or `null` if it was impossible to get it
|
|
18
22
|
*/
|
|
19
|
-
export async function getDefaultTask(
|
|
23
|
+
export async function getDefaultTask(
|
|
24
|
+
model: string,
|
|
25
|
+
accessToken: string | undefined,
|
|
26
|
+
options?: DefaultTaskOptions
|
|
27
|
+
): Promise<string | null> {
|
|
20
28
|
if (isUrl(model)) {
|
|
21
29
|
return null;
|
|
22
30
|
}
|
|
@@ -30,7 +38,7 @@ export async function getDefaultTask(model: string, accessToken: string | undefi
|
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
if (cachedTask === undefined) {
|
|
33
|
-
const modelTask = await fetch(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
41
|
+
const modelTask = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${model}?expand[]=pipeline_tag`, {
|
|
34
42
|
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
|
|
35
43
|
})
|
|
36
44
|
.then((resp) => resp.json())
|
|
@@ -25,7 +25,7 @@ export async function featureExtraction(
|
|
|
25
25
|
args: FeatureExtractionArgs,
|
|
26
26
|
options?: Options
|
|
27
27
|
): Promise<FeatureExtractionOutput> {
|
|
28
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : undefined;
|
|
28
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : undefined;
|
|
29
29
|
|
|
30
30
|
const res = await request<FeatureExtractionOutput>(args, {
|
|
31
31
|
...options,
|
|
@@ -25,7 +25,7 @@ export async function sentenceSimilarity(
|
|
|
25
25
|
args: SentenceSimilarityArgs,
|
|
26
26
|
options?: Options
|
|
27
27
|
): Promise<SentenceSimilarityOutput> {
|
|
28
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : undefined;
|
|
28
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : undefined;
|
|
29
29
|
const res = await request<SentenceSimilarityOutput>(args, {
|
|
30
30
|
...options,
|
|
31
31
|
taskHint: "sentence-similarity",
|
|
@@ -48,6 +48,10 @@ export type TextGenerationArgs = BaseArgs & {
|
|
|
48
48
|
* (Default: None). Integer. The maximum number of tokens from the input.
|
|
49
49
|
*/
|
|
50
50
|
truncate?: number;
|
|
51
|
+
/**
|
|
52
|
+
* (Default: []) List of strings. The model will stop generating text when one of the strings in the list is generated.
|
|
53
|
+
* **/
|
|
54
|
+
stop_sequences?: string[];
|
|
51
55
|
};
|
|
52
56
|
};
|
|
53
57
|
|
package/src/types.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface Options {
|
|
|
24
24
|
* Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
|
|
25
25
|
*/
|
|
26
26
|
fetch?: typeof fetch;
|
|
27
|
+
/**
|
|
28
|
+
* Abort Controller signal to use for request interruption.
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* (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.
|