@huggingface/inference 2.6.2 → 2.6.3
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.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) {
|
|
@@ -598,7 +598,7 @@ async function conversational(args, options) {
|
|
|
598
598
|
|
|
599
599
|
// src/tasks/nlp/featureExtraction.ts
|
|
600
600
|
async function featureExtraction(args, options) {
|
|
601
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
601
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
602
602
|
const res = await request(args, {
|
|
603
603
|
...options,
|
|
604
604
|
taskHint: "feature-extraction",
|
|
@@ -653,7 +653,7 @@ async function questionAnswering(args, options) {
|
|
|
653
653
|
|
|
654
654
|
// src/tasks/nlp/sentenceSimilarity.ts
|
|
655
655
|
async function sentenceSimilarity(args, options) {
|
|
656
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
656
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
657
657
|
const res = await request(args, {
|
|
658
658
|
...options,
|
|
659
659
|
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) {
|
|
@@ -546,7 +546,7 @@ async function conversational(args, options) {
|
|
|
546
546
|
|
|
547
547
|
// src/tasks/nlp/featureExtraction.ts
|
|
548
548
|
async function featureExtraction(args, options) {
|
|
549
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
549
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
550
550
|
const res = await request(args, {
|
|
551
551
|
...options,
|
|
552
552
|
taskHint: "feature-extraction",
|
|
@@ -601,7 +601,7 @@ async function questionAnswering(args, options) {
|
|
|
601
601
|
|
|
602
602
|
// src/tasks/nlp/sentenceSimilarity.ts
|
|
603
603
|
async function sentenceSimilarity(args, options) {
|
|
604
|
-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken) : void 0;
|
|
604
|
+
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : void 0;
|
|
605
605
|
const res = await request(args, {
|
|
606
606
|
...options,
|
|
607
607
|
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",
|