@huggingface/tasks 0.15.8 → 0.16.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/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 +10 -9
- 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 +16 -14
- 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 +59 -16
- 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 +10 -9
- 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 +16 -14
- 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 +60 -17
- 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 +18 -14
- package/src/snippets/js.ts +40 -35
- package/src/snippets/python.ts +85 -32
- 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/js.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { openAIbaseUrl, type
|
|
2
|
-
import type { PipelineType } from "../pipelines.js";
|
|
1
|
+
import { openAIbaseUrl, type SnippetInferenceProvider } from "../inference-providers.js";
|
|
2
|
+
import type { PipelineType, WidgetType } from "../pipelines.js";
|
|
3
3
|
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
|
|
4
4
|
import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
|
|
5
5
|
import { getModelInputSnippet } from "./inputs.js";
|
|
6
6
|
import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
|
|
7
7
|
|
|
8
|
-
const HFJS_METHODS: Record<
|
|
8
|
+
const HFJS_METHODS: Partial<Record<WidgetType, string>> = {
|
|
9
9
|
"text-classification": "textClassification",
|
|
10
10
|
"token-classification": "tokenClassification",
|
|
11
11
|
"table-question-answering": "tableQuestionAnswering",
|
|
@@ -22,14 +22,14 @@ const HFJS_METHODS: Record<string, string> = {
|
|
|
22
22
|
export const snippetBasic = (
|
|
23
23
|
model: ModelDataMinimal,
|
|
24
24
|
accessToken: string,
|
|
25
|
-
provider:
|
|
25
|
+
provider: SnippetInferenceProvider
|
|
26
26
|
): InferenceSnippet[] => {
|
|
27
27
|
return [
|
|
28
28
|
...(model.pipeline_tag && model.pipeline_tag in HFJS_METHODS
|
|
29
29
|
? [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
{
|
|
31
|
+
client: "huggingface.js",
|
|
32
|
+
content: `\
|
|
33
33
|
import { HfInference } from "@huggingface/inference";
|
|
34
34
|
|
|
35
35
|
const client = new HfInference("${accessToken || `{API_TOKEN}`}");
|
|
@@ -40,17 +40,17 @@ const output = await client.${HFJS_METHODS[model.pipeline_tag]}({
|
|
|
40
40
|
provider: "${provider}",
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
console.log(output)
|
|
43
|
+
console.log(output);
|
|
44
44
|
`,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
47
|
: []),
|
|
48
48
|
{
|
|
49
49
|
client: "fetch",
|
|
50
50
|
content: `\
|
|
51
51
|
async function query(data) {
|
|
52
52
|
const response = await fetch(
|
|
53
|
-
"https://
|
|
53
|
+
"https://router.huggingface.co/hf-inference/models/${model.id}",
|
|
54
54
|
{
|
|
55
55
|
headers: {
|
|
56
56
|
Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
|
|
@@ -74,7 +74,8 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
|
74
74
|
export const snippetTextGeneration = (
|
|
75
75
|
model: ModelDataMinimal,
|
|
76
76
|
accessToken: string,
|
|
77
|
-
provider:
|
|
77
|
+
provider: SnippetInferenceProvider,
|
|
78
|
+
providerModelId?: string,
|
|
78
79
|
opts?: {
|
|
79
80
|
streaming?: boolean;
|
|
80
81
|
messages?: ChatCompletionInputMessage[];
|
|
@@ -137,9 +138,9 @@ const client = new OpenAI({
|
|
|
137
138
|
let out = "";
|
|
138
139
|
|
|
139
140
|
const stream = await client.chat.completions.create({
|
|
140
|
-
model: "${model.id}",
|
|
141
|
+
model: "${providerModelId ?? model.id}",
|
|
141
142
|
messages: ${messagesStr},
|
|
142
|
-
${configStr}
|
|
143
|
+
${configStr}
|
|
143
144
|
stream: true,
|
|
144
145
|
});
|
|
145
146
|
|
|
@@ -167,7 +168,8 @@ const chatCompletion = await client.chatCompletion({
|
|
|
167
168
|
${configStr}
|
|
168
169
|
});
|
|
169
170
|
|
|
170
|
-
console.log(chatCompletion.choices[0].message)
|
|
171
|
+
console.log(chatCompletion.choices[0].message);
|
|
172
|
+
`,
|
|
171
173
|
},
|
|
172
174
|
{
|
|
173
175
|
client: "openai",
|
|
@@ -179,12 +181,13 @@ const client = new OpenAI({
|
|
|
179
181
|
});
|
|
180
182
|
|
|
181
183
|
const chatCompletion = await client.chat.completions.create({
|
|
182
|
-
model: "${model.id}",
|
|
184
|
+
model: "${providerModelId ?? model.id}",
|
|
183
185
|
messages: ${messagesStr},
|
|
184
186
|
${configStr}
|
|
185
187
|
});
|
|
186
188
|
|
|
187
|
-
console.log(chatCompletion.choices[0].message)
|
|
189
|
+
console.log(chatCompletion.choices[0].message);
|
|
190
|
+
`,
|
|
188
191
|
},
|
|
189
192
|
];
|
|
190
193
|
}
|
|
@@ -199,7 +202,7 @@ export const snippetZeroShotClassification = (model: ModelDataMinimal, accessTok
|
|
|
199
202
|
client: "fetch",
|
|
200
203
|
content: `async function query(data) {
|
|
201
204
|
const response = await fetch(
|
|
202
|
-
"https://
|
|
205
|
+
"https://router.huggingface.co/hf-inference/models/${model.id}",
|
|
203
206
|
{
|
|
204
207
|
headers: {
|
|
205
208
|
Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
|
|
@@ -214,8 +217,8 @@ export const snippetZeroShotClassification = (model: ModelDataMinimal, accessTok
|
|
|
214
217
|
}
|
|
215
218
|
|
|
216
219
|
query({"inputs": ${getModelInputSnippet(
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
model
|
|
221
|
+
)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}).then((response) => {
|
|
219
222
|
console.log(JSON.stringify(response));
|
|
220
223
|
});`,
|
|
221
224
|
},
|
|
@@ -225,7 +228,7 @@ export const snippetZeroShotClassification = (model: ModelDataMinimal, accessTok
|
|
|
225
228
|
export const snippetTextToImage = (
|
|
226
229
|
model: ModelDataMinimal,
|
|
227
230
|
accessToken: string,
|
|
228
|
-
provider:
|
|
231
|
+
provider: SnippetInferenceProvider
|
|
229
232
|
): InferenceSnippet[] => {
|
|
230
233
|
return [
|
|
231
234
|
{
|
|
@@ -246,11 +249,11 @@ const image = await client.textToImage({
|
|
|
246
249
|
},
|
|
247
250
|
...(provider === "hf-inference"
|
|
248
251
|
? [
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
+
{
|
|
253
|
+
client: "fetch",
|
|
254
|
+
content: `async function query(data) {
|
|
252
255
|
const response = await fetch(
|
|
253
|
-
"https://
|
|
256
|
+
"https://router.huggingface.co/hf-inference/models/${model.id}",
|
|
254
257
|
{
|
|
255
258
|
headers: {
|
|
256
259
|
Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
|
|
@@ -266,8 +269,8 @@ const image = await client.textToImage({
|
|
|
266
269
|
query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
267
270
|
// Use image
|
|
268
271
|
});`,
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
},
|
|
273
|
+
]
|
|
271
274
|
: []),
|
|
272
275
|
];
|
|
273
276
|
};
|
|
@@ -275,14 +278,14 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
|
275
278
|
export const snippetTextToAudio = (
|
|
276
279
|
model: ModelDataMinimal,
|
|
277
280
|
accessToken: string,
|
|
278
|
-
provider:
|
|
281
|
+
provider: SnippetInferenceProvider
|
|
279
282
|
): InferenceSnippet[] => {
|
|
280
283
|
if (provider !== "hf-inference") {
|
|
281
284
|
return [];
|
|
282
285
|
}
|
|
283
286
|
const commonSnippet = `async function query(data) {
|
|
284
287
|
const response = await fetch(
|
|
285
|
-
"https://
|
|
288
|
+
"https://router.huggingface.co/hf-inference/models/${model.id}",
|
|
286
289
|
{
|
|
287
290
|
headers: {
|
|
288
291
|
Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
|
|
@@ -329,7 +332,7 @@ export const snippetTextToAudio = (
|
|
|
329
332
|
export const snippetAutomaticSpeechRecognition = (
|
|
330
333
|
model: ModelDataMinimal,
|
|
331
334
|
accessToken: string,
|
|
332
|
-
provider:
|
|
335
|
+
provider: SnippetInferenceProvider
|
|
333
336
|
): InferenceSnippet[] => {
|
|
334
337
|
return [
|
|
335
338
|
{
|
|
@@ -357,7 +360,7 @@ console.log(output);
|
|
|
357
360
|
export const snippetFile = (
|
|
358
361
|
model: ModelDataMinimal,
|
|
359
362
|
accessToken: string,
|
|
360
|
-
provider:
|
|
363
|
+
provider: SnippetInferenceProvider
|
|
361
364
|
): InferenceSnippet[] => {
|
|
362
365
|
if (provider !== "hf-inference") {
|
|
363
366
|
return [];
|
|
@@ -368,7 +371,7 @@ export const snippetFile = (
|
|
|
368
371
|
content: `async function query(filename) {
|
|
369
372
|
const data = fs.readFileSync(filename);
|
|
370
373
|
const response = await fetch(
|
|
371
|
-
"https://
|
|
374
|
+
"https://router.huggingface.co/hf-inference/models/${model.id}",
|
|
372
375
|
{
|
|
373
376
|
headers: {
|
|
374
377
|
Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
|
|
@@ -395,7 +398,8 @@ export const jsSnippets: Partial<
|
|
|
395
398
|
(
|
|
396
399
|
model: ModelDataMinimal,
|
|
397
400
|
accessToken: string,
|
|
398
|
-
provider:
|
|
401
|
+
provider: SnippetInferenceProvider,
|
|
402
|
+
providerModelId?: string,
|
|
399
403
|
opts?: Record<string, unknown>
|
|
400
404
|
) => InferenceSnippet[]
|
|
401
405
|
>
|
|
@@ -429,10 +433,11 @@ export const jsSnippets: Partial<
|
|
|
429
433
|
export function getJsInferenceSnippet(
|
|
430
434
|
model: ModelDataMinimal,
|
|
431
435
|
accessToken: string,
|
|
432
|
-
provider:
|
|
436
|
+
provider: SnippetInferenceProvider,
|
|
437
|
+
providerModelId?: string,
|
|
433
438
|
opts?: Record<string, unknown>
|
|
434
439
|
): InferenceSnippet[] {
|
|
435
440
|
return model.pipeline_tag && model.pipeline_tag in jsSnippets
|
|
436
|
-
? jsSnippets[model.pipeline_tag]?.(model, accessToken, provider, opts) ?? []
|
|
441
|
+
? jsSnippets[model.pipeline_tag]?.(model, accessToken, provider, providerModelId, opts) ?? []
|
|
437
442
|
: [];
|
|
438
443
|
}
|
package/src/snippets/python.ts
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
openAIbaseUrl,
|
|
3
|
+
type SnippetInferenceProvider,
|
|
4
|
+
} from "../inference-providers.js";
|
|
5
|
+
import type { PipelineType, WidgetType } from "../pipelines.js";
|
|
3
6
|
import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
|
|
4
7
|
import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
|
|
5
8
|
import { getModelInputSnippet } from "./inputs.js";
|
|
6
9
|
import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
|
|
7
10
|
|
|
8
|
-
const
|
|
11
|
+
const HFH_INFERENCE_CLIENT_METHODS: Partial<Record<WidgetType, string>> = {
|
|
12
|
+
"audio-classification": "audio_classification",
|
|
13
|
+
"audio-to-audio": "audio_to_audio",
|
|
14
|
+
"automatic-speech-recognition": "automatic_speech_recognition",
|
|
15
|
+
"text-to-speech": "text_to_speech",
|
|
16
|
+
"image-classification": "image_classification",
|
|
17
|
+
"image-segmentation": "image_segmentation",
|
|
18
|
+
"image-to-image": "image_to_image",
|
|
19
|
+
"image-to-text": "image_to_text",
|
|
20
|
+
"object-detection": "object_detection",
|
|
21
|
+
"text-to-image": "text_to_image",
|
|
22
|
+
"text-to-video": "text_to_video",
|
|
23
|
+
"zero-shot-image-classification": "zero_shot_image_classification",
|
|
24
|
+
"document-question-answering": "document_question_answering",
|
|
25
|
+
"visual-question-answering": "visual_question_answering",
|
|
26
|
+
"feature-extraction": "feature_extraction",
|
|
27
|
+
"fill-mask": "fill_mask",
|
|
28
|
+
"question-answering": "question_answering",
|
|
29
|
+
"sentence-similarity": "sentence_similarity",
|
|
30
|
+
summarization: "summarization",
|
|
31
|
+
"table-question-answering": "table_question_answering",
|
|
32
|
+
"text-classification": "text_classification",
|
|
33
|
+
"text-generation": "text_generation",
|
|
34
|
+
"token-classification": "token_classification",
|
|
35
|
+
translation: "translation",
|
|
36
|
+
"zero-shot-classification": "zero_shot_classification",
|
|
37
|
+
"tabular-classification": "tabular_classification",
|
|
38
|
+
"tabular-regression": "tabular_regression",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const snippetImportInferenceClient = (accessToken: string, provider: SnippetInferenceProvider): string =>
|
|
9
42
|
`\
|
|
10
43
|
from huggingface_hub import InferenceClient
|
|
11
44
|
|
|
@@ -17,7 +50,8 @@ client = InferenceClient(
|
|
|
17
50
|
export const snippetConversational = (
|
|
18
51
|
model: ModelDataMinimal,
|
|
19
52
|
accessToken: string,
|
|
20
|
-
provider:
|
|
53
|
+
provider: SnippetInferenceProvider,
|
|
54
|
+
providerModelId?: string,
|
|
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
|
|
|
@@ -73,9 +107,9 @@ client = OpenAI(
|
|
|
73
107
|
messages = ${messagesStr}
|
|
74
108
|
|
|
75
109
|
stream = client.chat.completions.create(
|
|
76
|
-
model="${model.id}",
|
|
110
|
+
model="${providerModelId ?? model.id}",
|
|
77
111
|
messages=messages,
|
|
78
|
-
${configStr}
|
|
112
|
+
${configStr}
|
|
79
113
|
stream=True
|
|
80
114
|
)
|
|
81
115
|
|
|
@@ -113,7 +147,7 @@ client = OpenAI(
|
|
|
113
147
|
messages = ${messagesStr}
|
|
114
148
|
|
|
115
149
|
completion = client.chat.completions.create(
|
|
116
|
-
model="${model.id}",
|
|
150
|
+
model="${providerModelId ?? model.id}",
|
|
117
151
|
messages=messages,
|
|
118
152
|
${configStr}
|
|
119
153
|
)
|
|
@@ -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,8 @@ output = query(${getModelInputSnippet(model)})`,
|
|
|
199
255
|
export const snippetTextToImage = (
|
|
200
256
|
model: ModelDataMinimal,
|
|
201
257
|
accessToken: string,
|
|
202
|
-
provider:
|
|
258
|
+
provider: SnippetInferenceProvider,
|
|
259
|
+
providerModelId?: string,
|
|
203
260
|
): InferenceSnippet[] => {
|
|
204
261
|
return [
|
|
205
262
|
{
|
|
@@ -215,28 +272,27 @@ image = client.text_to_image(
|
|
|
215
272
|
},
|
|
216
273
|
...(provider === "fal-ai"
|
|
217
274
|
? [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
275
|
+
{
|
|
276
|
+
client: "fal-client",
|
|
277
|
+
content: `\
|
|
221
278
|
import fal_client
|
|
222
279
|
|
|
223
280
|
result = fal_client.subscribe(
|
|
224
|
-
|
|
225
|
-
"fal-ai/${model.id}",
|
|
281
|
+
"${providerModelId ?? model.id}",
|
|
226
282
|
arguments={
|
|
227
283
|
"prompt": ${getModelInputSnippet(model)},
|
|
228
284
|
},
|
|
229
285
|
)
|
|
230
286
|
print(result)
|
|
231
287
|
`,
|
|
232
|
-
|
|
233
|
-
|
|
288
|
+
},
|
|
289
|
+
]
|
|
234
290
|
: []),
|
|
235
291
|
...(provider === "hf-inference"
|
|
236
292
|
? [
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
293
|
+
{
|
|
294
|
+
client: "requests",
|
|
295
|
+
content: `\
|
|
240
296
|
def query(payload):
|
|
241
297
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
242
298
|
return response.content
|
|
@@ -249,8 +305,8 @@ image_bytes = query({
|
|
|
249
305
|
import io
|
|
250
306
|
from PIL import Image
|
|
251
307
|
image = Image.open(io.BytesIO(image_bytes))`,
|
|
252
|
-
|
|
253
|
-
|
|
308
|
+
},
|
|
309
|
+
]
|
|
254
310
|
: []),
|
|
255
311
|
];
|
|
256
312
|
};
|
|
@@ -337,7 +393,8 @@ export const pythonSnippets: Partial<
|
|
|
337
393
|
(
|
|
338
394
|
model: ModelDataMinimal,
|
|
339
395
|
accessToken: string,
|
|
340
|
-
provider:
|
|
396
|
+
provider: SnippetInferenceProvider,
|
|
397
|
+
providerModelId?: string,
|
|
341
398
|
opts?: Record<string, unknown>
|
|
342
399
|
) => InferenceSnippet[]
|
|
343
400
|
>
|
|
@@ -375,23 +432,19 @@ export const pythonSnippets: Partial<
|
|
|
375
432
|
export function getPythonInferenceSnippet(
|
|
376
433
|
model: ModelDataMinimal,
|
|
377
434
|
accessToken: string,
|
|
378
|
-
provider:
|
|
435
|
+
provider: SnippetInferenceProvider,
|
|
436
|
+
providerModelId?: string,
|
|
379
437
|
opts?: Record<string, unknown>
|
|
380
438
|
): InferenceSnippet[] {
|
|
381
439
|
if (model.tags.includes("conversational")) {
|
|
382
440
|
// Conversational model detected, so we display a code snippet that features the Messages API
|
|
383
|
-
return snippetConversational(model, accessToken, provider, opts);
|
|
441
|
+
return snippetConversational(model, accessToken, provider, providerModelId, opts);
|
|
384
442
|
} else {
|
|
385
443
|
const snippets =
|
|
386
444
|
model.pipeline_tag && model.pipeline_tag in pythonSnippets
|
|
387
|
-
? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider) ?? []
|
|
445
|
+
? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider, providerModelId) ?? []
|
|
388
446
|
: [];
|
|
389
447
|
|
|
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
448
|
return snippets.map((snippet) => {
|
|
396
449
|
return {
|
|
397
450
|
...snippet,
|
|
@@ -400,7 +453,7 @@ export function getPythonInferenceSnippet(
|
|
|
400
453
|
? `\
|
|
401
454
|
import requests
|
|
402
455
|
|
|
403
|
-
API_URL = "${
|
|
456
|
+
API_URL = "${openAIbaseUrl(provider)}"
|
|
404
457
|
headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
|
|
405
458
|
|
|
406
459
|
${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)
|