@huggingface/tasks 0.15.8 → 0.15.9
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/commonjs/inference-providers.d.ts +5 -4
- package/dist/commonjs/inference-providers.d.ts.map +1 -1
- package/dist/commonjs/inference-providers.js +15 -6
- package/dist/commonjs/library-to-tasks.d.ts +1 -1
- package/dist/commonjs/library-to-tasks.js +1 -1
- package/dist/commonjs/model-libraries-snippets.d.ts +1 -0
- package/dist/commonjs/model-libraries-snippets.d.ts.map +1 -1
- package/dist/commonjs/model-libraries-snippets.js +16 -2
- package/dist/commonjs/model-libraries.d.ts +8 -1
- package/dist/commonjs/model-libraries.d.ts.map +1 -1
- package/dist/commonjs/model-libraries.js +7 -0
- package/dist/commonjs/pipelines.d.ts +7 -1
- package/dist/commonjs/pipelines.d.ts.map +1 -1
- package/dist/commonjs/pipelines.js +6 -0
- package/dist/commonjs/snippets/common.js +2 -2
- package/dist/commonjs/snippets/curl.d.ts +7 -7
- package/dist/commonjs/snippets/curl.d.ts.map +1 -1
- package/dist/commonjs/snippets/curl.js +5 -5
- package/dist/commonjs/snippets/js.d.ts +9 -9
- package/dist/commonjs/snippets/js.d.ts.map +1 -1
- package/dist/commonjs/snippets/js.js +11 -9
- package/dist/commonjs/snippets/python.d.ts +6 -6
- package/dist/commonjs/snippets/python.d.ts.map +1 -1
- package/dist/commonjs/snippets/python.js +51 -7
- package/dist/commonjs/tasks/index.d.ts.map +1 -1
- package/dist/commonjs/tasks/index.js +2 -0
- package/dist/commonjs/tasks/text-generation/data.d.ts.map +1 -1
- package/dist/commonjs/tasks/text-generation/data.js +1 -3
- package/dist/esm/inference-providers.d.ts +5 -4
- package/dist/esm/inference-providers.d.ts.map +1 -1
- package/dist/esm/inference-providers.js +14 -5
- package/dist/esm/library-to-tasks.d.ts +1 -1
- package/dist/esm/library-to-tasks.js +1 -1
- package/dist/esm/model-libraries-snippets.d.ts +1 -0
- package/dist/esm/model-libraries-snippets.d.ts.map +1 -1
- package/dist/esm/model-libraries-snippets.js +13 -0
- package/dist/esm/model-libraries.d.ts +8 -1
- package/dist/esm/model-libraries.d.ts.map +1 -1
- package/dist/esm/model-libraries.js +7 -0
- package/dist/esm/pipelines.d.ts +7 -1
- package/dist/esm/pipelines.d.ts.map +1 -1
- package/dist/esm/pipelines.js +6 -0
- package/dist/esm/snippets/common.js +2 -2
- package/dist/esm/snippets/curl.d.ts +7 -7
- package/dist/esm/snippets/curl.d.ts.map +1 -1
- package/dist/esm/snippets/curl.js +5 -5
- package/dist/esm/snippets/js.d.ts +9 -9
- package/dist/esm/snippets/js.d.ts.map +1 -1
- package/dist/esm/snippets/js.js +11 -9
- package/dist/esm/snippets/python.d.ts +6 -6
- package/dist/esm/snippets/python.d.ts.map +1 -1
- package/dist/esm/snippets/python.js +52 -8
- package/dist/esm/tasks/index.d.ts.map +1 -1
- package/dist/esm/tasks/index.js +2 -0
- package/dist/esm/tasks/text-generation/data.d.ts.map +1 -1
- package/dist/esm/tasks/text-generation/data.js +1 -3
- package/package.json +1 -1
- package/src/inference-providers.ts +16 -7
- package/src/library-to-tasks.ts +1 -1
- package/src/model-libraries-snippets.ts +14 -0
- package/src/model-libraries.ts +7 -0
- package/src/pipelines.ts +6 -0
- package/src/snippets/common.ts +2 -2
- package/src/snippets/curl.ts +19 -19
- package/src/snippets/js.ts +22 -20
- package/src/snippets/python.ts +67 -16
- package/src/tasks/audio-classification/about.md +1 -1
- package/src/tasks/audio-to-audio/about.md +1 -1
- package/src/tasks/automatic-speech-recognition/about.md +1 -1
- package/src/tasks/feature-extraction/spec/input.json +11 -4
- package/src/tasks/image-text-to-text/about.md +1 -1
- package/src/tasks/index.ts +2 -0
- package/src/tasks/sentence-similarity/about.md +2 -2
- package/src/tasks/text-generation/data.ts +1 -3
- package/src/tasks/text-to-speech/about.md +1 -1
package/src/snippets/python.ts
CHANGED
|
@@ -1,11 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
HF_HUB_INFERENCE_PROXY_TEMPLATE,
|
|
3
|
+
openAIbaseUrl,
|
|
4
|
+
type SnippetInferenceProvider,
|
|
5
|
+
} from "../inference-providers.js";
|
|
6
|
+
import type { PipelineType, WidgetType } from "../pipelines.js";
|
|
3
7
|
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
|
|
4
8
|
import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
|
|
5
9
|
import { getModelInputSnippet } from "./inputs.js";
|
|
6
10
|
import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
|
|
7
11
|
|
|
8
|
-
const
|
|
12
|
+
const HFH_INFERENCE_CLIENT_METHODS: Partial<Record<WidgetType, string>> = {
|
|
13
|
+
"audio-classification": "audio_classification",
|
|
14
|
+
"audio-to-audio": "audio_to_audio",
|
|
15
|
+
"automatic-speech-recognition": "automatic_speech_recognition",
|
|
16
|
+
"text-to-speech": "text_to_speech",
|
|
17
|
+
"image-classification": "image_classification",
|
|
18
|
+
"image-segmentation": "image_segmentation",
|
|
19
|
+
"image-to-image": "image_to_image",
|
|
20
|
+
"image-to-text": "image_to_text",
|
|
21
|
+
"object-detection": "object_detection",
|
|
22
|
+
"text-to-image": "text_to_image",
|
|
23
|
+
"text-to-video": "text_to_video",
|
|
24
|
+
"zero-shot-image-classification": "zero_shot_image_classification",
|
|
25
|
+
"document-question-answering": "document_question_answering",
|
|
26
|
+
"visual-question-answering": "visual_question_answering",
|
|
27
|
+
"feature-extraction": "feature_extraction",
|
|
28
|
+
"fill-mask": "fill_mask",
|
|
29
|
+
"question-answering": "question_answering",
|
|
30
|
+
"sentence-similarity": "sentence_similarity",
|
|
31
|
+
summarization: "summarization",
|
|
32
|
+
"table-question-answering": "table_question_answering",
|
|
33
|
+
"text-classification": "text_classification",
|
|
34
|
+
"text-generation": "text_generation",
|
|
35
|
+
"token-classification": "token_classification",
|
|
36
|
+
translation: "translation",
|
|
37
|
+
"zero-shot-classification": "zero_shot_classification",
|
|
38
|
+
"tabular-classification": "tabular_classification",
|
|
39
|
+
"tabular-regression": "tabular_regression",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const snippetImportInferenceClient = (accessToken: string, provider: SnippetInferenceProvider): string =>
|
|
9
43
|
`\
|
|
10
44
|
from huggingface_hub import InferenceClient
|
|
11
45
|
|
|
@@ -17,7 +51,7 @@ client = InferenceClient(
|
|
|
17
51
|
export const snippetConversational = (
|
|
18
52
|
model: ModelDataMinimal,
|
|
19
53
|
accessToken: string,
|
|
20
|
-
provider:
|
|
54
|
+
provider: SnippetInferenceProvider,
|
|
21
55
|
opts?: {
|
|
22
56
|
streaming?: boolean;
|
|
23
57
|
messages?: ChatCompletionInputMessage[];
|
|
@@ -53,7 +87,7 @@ messages = ${messagesStr}
|
|
|
53
87
|
stream = client.chat.completions.create(
|
|
54
88
|
model="${model.id}",
|
|
55
89
|
messages=messages,
|
|
56
|
-
${configStr}
|
|
90
|
+
${configStr}
|
|
57
91
|
stream=True
|
|
58
92
|
)
|
|
59
93
|
|
|
@@ -75,7 +109,7 @@ messages = ${messagesStr}
|
|
|
75
109
|
stream = client.chat.completions.create(
|
|
76
110
|
model="${model.id}",
|
|
77
111
|
messages=messages,
|
|
78
|
-
${configStr}
|
|
112
|
+
${configStr}
|
|
79
113
|
stream=True
|
|
80
114
|
)
|
|
81
115
|
|
|
@@ -164,8 +198,30 @@ output = query({
|
|
|
164
198
|
];
|
|
165
199
|
};
|
|
166
200
|
|
|
167
|
-
export const snippetBasic = (
|
|
201
|
+
export const snippetBasic = (
|
|
202
|
+
model: ModelDataMinimal,
|
|
203
|
+
accessToken: string,
|
|
204
|
+
provider: SnippetInferenceProvider
|
|
205
|
+
): InferenceSnippet[] => {
|
|
168
206
|
return [
|
|
207
|
+
...(model.pipeline_tag && model.pipeline_tag in HFH_INFERENCE_CLIENT_METHODS
|
|
208
|
+
? [
|
|
209
|
+
{
|
|
210
|
+
client: "huggingface_hub",
|
|
211
|
+
content: `\
|
|
212
|
+
${snippetImportInferenceClient(accessToken, provider)}
|
|
213
|
+
|
|
214
|
+
result = client.${HFH_INFERENCE_CLIENT_METHODS[model.pipeline_tag]}(
|
|
215
|
+
model="${model.id}",
|
|
216
|
+
inputs=${getModelInputSnippet(model)},
|
|
217
|
+
provider="${provider}",
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
print(result)
|
|
221
|
+
`,
|
|
222
|
+
},
|
|
223
|
+
]
|
|
224
|
+
: []),
|
|
169
225
|
{
|
|
170
226
|
client: "requests",
|
|
171
227
|
content: `\
|
|
@@ -199,7 +255,7 @@ output = query(${getModelInputSnippet(model)})`,
|
|
|
199
255
|
export const snippetTextToImage = (
|
|
200
256
|
model: ModelDataMinimal,
|
|
201
257
|
accessToken: string,
|
|
202
|
-
provider:
|
|
258
|
+
provider: SnippetInferenceProvider
|
|
203
259
|
): InferenceSnippet[] => {
|
|
204
260
|
return [
|
|
205
261
|
{
|
|
@@ -337,7 +393,7 @@ export const pythonSnippets: Partial<
|
|
|
337
393
|
(
|
|
338
394
|
model: ModelDataMinimal,
|
|
339
395
|
accessToken: string,
|
|
340
|
-
provider:
|
|
396
|
+
provider: SnippetInferenceProvider,
|
|
341
397
|
opts?: Record<string, unknown>
|
|
342
398
|
) => InferenceSnippet[]
|
|
343
399
|
>
|
|
@@ -375,7 +431,7 @@ export const pythonSnippets: Partial<
|
|
|
375
431
|
export function getPythonInferenceSnippet(
|
|
376
432
|
model: ModelDataMinimal,
|
|
377
433
|
accessToken: string,
|
|
378
|
-
provider:
|
|
434
|
+
provider: SnippetInferenceProvider,
|
|
379
435
|
opts?: Record<string, unknown>
|
|
380
436
|
): InferenceSnippet[] {
|
|
381
437
|
if (model.tags.includes("conversational")) {
|
|
@@ -387,11 +443,6 @@ export function getPythonInferenceSnippet(
|
|
|
387
443
|
? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider) ?? []
|
|
388
444
|
: [];
|
|
389
445
|
|
|
390
|
-
const baseUrl =
|
|
391
|
-
provider === "hf-inference"
|
|
392
|
-
? `https://api-inference.huggingface.co/models/${model.id}`
|
|
393
|
-
: HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider);
|
|
394
|
-
|
|
395
446
|
return snippets.map((snippet) => {
|
|
396
447
|
return {
|
|
397
448
|
...snippet,
|
|
@@ -400,7 +451,7 @@ export function getPythonInferenceSnippet(
|
|
|
400
451
|
? `\
|
|
401
452
|
import requests
|
|
402
453
|
|
|
403
|
-
API_URL = "${
|
|
454
|
+
API_URL = "${openAIbaseUrl(provider)}"
|
|
404
455
|
headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
|
|
405
456
|
|
|
406
457
|
${snippet.content}`
|
|
@@ -33,7 +33,7 @@ import json
|
|
|
33
33
|
import requests
|
|
34
34
|
|
|
35
35
|
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
36
|
-
API_URL = "https://
|
|
36
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/superb/hubert-large-superb-er"
|
|
37
37
|
|
|
38
38
|
def query(filename):
|
|
39
39
|
with open(filename, "rb") as f:
|
|
@@ -19,7 +19,7 @@ import json
|
|
|
19
19
|
import requests
|
|
20
20
|
|
|
21
21
|
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
22
|
-
API_URL = "https://
|
|
22
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/speechbrain/mtl-mimic-voicebank"
|
|
23
23
|
|
|
24
24
|
def query(filename):
|
|
25
25
|
with open(filename, "rb") as f:
|
|
@@ -25,7 +25,7 @@ import json
|
|
|
25
25
|
import requests
|
|
26
26
|
|
|
27
27
|
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
28
|
-
API_URL = "https://
|
|
28
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/openai/whisper-large-v3"
|
|
29
29
|
|
|
30
30
|
def query(filename):
|
|
31
31
|
with open(filename, "rb") as f:
|
|
@@ -8,11 +8,18 @@
|
|
|
8
8
|
"properties": {
|
|
9
9
|
"inputs": {
|
|
10
10
|
"title": "FeatureExtractionInputs",
|
|
11
|
+
"description": "The text or list of texts to embed.",
|
|
11
12
|
"oneOf": [
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
{
|
|
14
|
+
"type": "string"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "array",
|
|
18
|
+
"items": {
|
|
19
|
+
"type": "string"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
16
23
|
},
|
|
17
24
|
"normalize": {
|
|
18
25
|
"type": "boolean",
|
|
@@ -76,7 +76,7 @@ outputs[0]["generated_text"]
|
|
|
76
76
|
You can also use the Inference API to test image-text-to-text models. You need to use a [Hugging Face token](https://huggingface.co/settings/tokens) for authentication.
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
|
-
curl https://
|
|
79
|
+
curl https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.2-11B-Vision-Instruct \
|
|
80
80
|
-X POST \
|
|
81
81
|
-d '{"messages": [{"role": "user","content": [{"type": "image"}, {"type": "text", "text": "Can you describe the image?"}]}]}' \
|
|
82
82
|
-H "Content-Type: application/json" \
|
package/src/tasks/index.ts
CHANGED
|
@@ -174,6 +174,7 @@ export const TASKS_MODEL_LIBRARIES: Record<PipelineType, ModelLibraryKey[]> = {
|
|
|
174
174
|
"text-to-3d": ["diffusers"],
|
|
175
175
|
"image-to-3d": ["diffusers"],
|
|
176
176
|
"any-to-any": ["transformers"],
|
|
177
|
+
"visual-document-retrieval": ["transformers"],
|
|
177
178
|
};
|
|
178
179
|
|
|
179
180
|
/**
|
|
@@ -202,6 +203,7 @@ export const TASKS_DATA: Record<PipelineType, TaskData | undefined> = {
|
|
|
202
203
|
"automatic-speech-recognition": getData("automatic-speech-recognition", automaticSpeechRecognition),
|
|
203
204
|
"depth-estimation": getData("depth-estimation", depthEstimation),
|
|
204
205
|
"document-question-answering": getData("document-question-answering", documentQuestionAnswering),
|
|
206
|
+
"visual-document-retrieval": getData("visual-document-retrieval", placeholder),
|
|
205
207
|
"feature-extraction": getData("feature-extraction", featureExtraction),
|
|
206
208
|
"fill-mask": getData("fill-mask", fillMask),
|
|
207
209
|
"graph-ml": undefined,
|
|
@@ -22,7 +22,7 @@ You can infer with Passage Ranking models using [Inference Endpoints](https://hu
|
|
|
22
22
|
import json
|
|
23
23
|
import requests
|
|
24
24
|
|
|
25
|
-
API_URL = "https://
|
|
25
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/sentence-transformers/msmarco-distilbert-base-tas-b"
|
|
26
26
|
headers = {"Authorization": f"Bearer {api_token}"}
|
|
27
27
|
|
|
28
28
|
def query(payload):
|
|
@@ -51,7 +51,7 @@ Semantic Textual Similarity is the task of evaluating how similar two texts are
|
|
|
51
51
|
import json
|
|
52
52
|
import requests
|
|
53
53
|
|
|
54
|
-
API_URL = "https://
|
|
54
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2"
|
|
55
55
|
headers = {"Authorization": f"Bearer {api_token}"}
|
|
56
56
|
|
|
57
57
|
def query(payload):
|
|
@@ -61,9 +61,7 @@ const taskData: TaskDataCustom = {
|
|
|
61
61
|
},
|
|
62
62
|
],
|
|
63
63
|
models: [
|
|
64
|
-
{
|
|
65
|
-
id: "google/gemma-2-2b-it",
|
|
66
|
-
},
|
|
64
|
+
{ description: "A text-generation model trained to follow instructions.", id: "google/gemma-2-2b-it" },
|
|
67
65
|
{
|
|
68
66
|
description: "Smaller variant of one of the most powerful models.",
|
|
69
67
|
id: "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
|
@@ -19,7 +19,7 @@ import json
|
|
|
19
19
|
import requests
|
|
20
20
|
|
|
21
21
|
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
22
|
-
API_URL = "https://
|
|
22
|
+
API_URL = "https://router.huggingface.co/hf-inference/models/microsoft/speecht5_tts"
|
|
23
23
|
|
|
24
24
|
def query(payload):
|
|
25
25
|
response = requests.post(API_URL, headers=headers, json=payload)
|