@huggingface/tasks 0.15.7 → 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.
Files changed (75) hide show
  1. package/dist/commonjs/inference-providers.d.ts +5 -4
  2. package/dist/commonjs/inference-providers.d.ts.map +1 -1
  3. package/dist/commonjs/inference-providers.js +15 -6
  4. package/dist/commonjs/library-to-tasks.d.ts +1 -1
  5. package/dist/commonjs/library-to-tasks.js +1 -1
  6. package/dist/commonjs/model-libraries-snippets.d.ts +1 -0
  7. package/dist/commonjs/model-libraries-snippets.d.ts.map +1 -1
  8. package/dist/commonjs/model-libraries-snippets.js +22 -8
  9. package/dist/commonjs/model-libraries.d.ts +8 -1
  10. package/dist/commonjs/model-libraries.d.ts.map +1 -1
  11. package/dist/commonjs/model-libraries.js +7 -0
  12. package/dist/commonjs/pipelines.d.ts +7 -1
  13. package/dist/commonjs/pipelines.d.ts.map +1 -1
  14. package/dist/commonjs/pipelines.js +6 -0
  15. package/dist/commonjs/snippets/common.js +2 -2
  16. package/dist/commonjs/snippets/curl.d.ts +7 -7
  17. package/dist/commonjs/snippets/curl.d.ts.map +1 -1
  18. package/dist/commonjs/snippets/curl.js +5 -5
  19. package/dist/commonjs/snippets/js.d.ts +9 -9
  20. package/dist/commonjs/snippets/js.d.ts.map +1 -1
  21. package/dist/commonjs/snippets/js.js +11 -9
  22. package/dist/commonjs/snippets/python.d.ts +6 -6
  23. package/dist/commonjs/snippets/python.d.ts.map +1 -1
  24. package/dist/commonjs/snippets/python.js +51 -7
  25. package/dist/commonjs/tasks/index.d.ts.map +1 -1
  26. package/dist/commonjs/tasks/index.js +2 -0
  27. package/dist/commonjs/tasks/text-generation/data.d.ts.map +1 -1
  28. package/dist/commonjs/tasks/text-generation/data.js +1 -3
  29. package/dist/esm/inference-providers.d.ts +5 -4
  30. package/dist/esm/inference-providers.d.ts.map +1 -1
  31. package/dist/esm/inference-providers.js +14 -5
  32. package/dist/esm/library-to-tasks.d.ts +1 -1
  33. package/dist/esm/library-to-tasks.js +1 -1
  34. package/dist/esm/model-libraries-snippets.d.ts +1 -0
  35. package/dist/esm/model-libraries-snippets.d.ts.map +1 -1
  36. package/dist/esm/model-libraries-snippets.js +19 -6
  37. package/dist/esm/model-libraries.d.ts +8 -1
  38. package/dist/esm/model-libraries.d.ts.map +1 -1
  39. package/dist/esm/model-libraries.js +7 -0
  40. package/dist/esm/pipelines.d.ts +7 -1
  41. package/dist/esm/pipelines.d.ts.map +1 -1
  42. package/dist/esm/pipelines.js +6 -0
  43. package/dist/esm/snippets/common.js +2 -2
  44. package/dist/esm/snippets/curl.d.ts +7 -7
  45. package/dist/esm/snippets/curl.d.ts.map +1 -1
  46. package/dist/esm/snippets/curl.js +5 -5
  47. package/dist/esm/snippets/js.d.ts +9 -9
  48. package/dist/esm/snippets/js.d.ts.map +1 -1
  49. package/dist/esm/snippets/js.js +11 -9
  50. package/dist/esm/snippets/python.d.ts +6 -6
  51. package/dist/esm/snippets/python.d.ts.map +1 -1
  52. package/dist/esm/snippets/python.js +52 -8
  53. package/dist/esm/tasks/index.d.ts.map +1 -1
  54. package/dist/esm/tasks/index.js +2 -0
  55. package/dist/esm/tasks/text-generation/data.d.ts.map +1 -1
  56. package/dist/esm/tasks/text-generation/data.js +1 -3
  57. package/package.json +1 -1
  58. package/src/inference-providers.ts +16 -7
  59. package/src/library-to-tasks.ts +1 -1
  60. package/src/model-libraries-snippets.ts +20 -6
  61. package/src/model-libraries.ts +7 -0
  62. package/src/pipelines.ts +6 -0
  63. package/src/snippets/common.ts +2 -2
  64. package/src/snippets/curl.ts +19 -19
  65. package/src/snippets/js.ts +22 -20
  66. package/src/snippets/python.ts +67 -16
  67. package/src/tasks/audio-classification/about.md +1 -1
  68. package/src/tasks/audio-to-audio/about.md +1 -1
  69. package/src/tasks/automatic-speech-recognition/about.md +1 -1
  70. package/src/tasks/feature-extraction/spec/input.json +11 -4
  71. package/src/tasks/image-text-to-text/about.md +1 -1
  72. package/src/tasks/index.ts +2 -0
  73. package/src/tasks/sentence-similarity/about.md +2 -2
  74. package/src/tasks/text-generation/data.ts +1 -3
  75. package/src/tasks/text-to-speech/about.md +1 -1
@@ -31,7 +31,7 @@ const output = await client.${HFJS_METHODS[model.pipeline_tag]}({
31
31
  provider: "${provider}",
32
32
  });
33
33
 
34
- console.log(output)
34
+ console.log(output);
35
35
  `,
36
36
  },
37
37
  ]
@@ -41,7 +41,7 @@ console.log(output)
41
41
  content: `\
42
42
  async function query(data) {
43
43
  const response = await fetch(
44
- "https://api-inference.huggingface.co/models/${model.id}",
44
+ "https://router.huggingface.co/hf-inference/models/${model.id}",
45
45
  {
46
46
  headers: {
47
47
  Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
@@ -116,7 +116,7 @@ let out = "";
116
116
  const stream = await client.chat.completions.create({
117
117
  model: "${model.id}",
118
118
  messages: ${messagesStr},
119
- ${configStr},
119
+ ${configStr}
120
120
  stream: true,
121
121
  });
122
122
 
@@ -145,7 +145,8 @@ const chatCompletion = await client.chatCompletion({
145
145
  ${configStr}
146
146
  });
147
147
 
148
- console.log(chatCompletion.choices[0].message);`,
148
+ console.log(chatCompletion.choices[0].message);
149
+ `,
149
150
  },
150
151
  {
151
152
  client: "openai",
@@ -162,7 +163,8 @@ const chatCompletion = await client.chat.completions.create({
162
163
  ${configStr}
163
164
  });
164
165
 
165
- console.log(chatCompletion.choices[0].message);`,
166
+ console.log(chatCompletion.choices[0].message);
167
+ `,
166
168
  },
167
169
  ];
168
170
  }
@@ -177,7 +179,7 @@ export const snippetZeroShotClassification = (model, accessToken) => {
177
179
  client: "fetch",
178
180
  content: `async function query(data) {
179
181
  const response = await fetch(
180
- "https://api-inference.huggingface.co/models/${model.id}",
182
+ "https://router.huggingface.co/hf-inference/models/${model.id}",
181
183
  {
182
184
  headers: {
183
185
  Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
@@ -221,7 +223,7 @@ const image = await client.textToImage({
221
223
  client: "fetch",
222
224
  content: `async function query(data) {
223
225
  const response = await fetch(
224
- "https://api-inference.huggingface.co/models/${model.id}",
226
+ "https://router.huggingface.co/hf-inference/models/${model.id}",
225
227
  {
226
228
  headers: {
227
229
  Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
@@ -248,7 +250,7 @@ export const snippetTextToAudio = (model, accessToken, provider) => {
248
250
  }
249
251
  const commonSnippet = `async function query(data) {
250
252
  const response = await fetch(
251
- "https://api-inference.huggingface.co/models/${model.id}",
253
+ "https://router.huggingface.co/hf-inference/models/${model.id}",
252
254
  {
253
255
  headers: {
254
256
  Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
@@ -323,7 +325,7 @@ export const snippetFile = (model, accessToken, provider) => {
323
325
  content: `async function query(filename) {
324
326
  const data = fs.readFileSync(filename);
325
327
  const response = await fetch(
326
- "https://api-inference.huggingface.co/models/${model.id}",
328
+ "https://router.huggingface.co/hf-inference/models/${model.id}",
327
329
  {
328
330
  headers: {
329
331
  Authorization: "Bearer ${accessToken || `{API_TOKEN}`}",
@@ -1,8 +1,8 @@
1
- import { type InferenceProvider } from "../inference-providers.js";
1
+ import { type SnippetInferenceProvider } from "../inference-providers.js";
2
2
  import type { PipelineType } from "../pipelines.js";
3
3
  import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
4
4
  import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
5
- export declare const snippetConversational: (model: ModelDataMinimal, accessToken: string, provider: InferenceProvider, opts?: {
5
+ export declare const snippetConversational: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, opts?: {
6
6
  streaming?: boolean;
7
7
  messages?: ChatCompletionInputMessage[];
8
8
  temperature?: GenerationParameters["temperature"];
@@ -11,12 +11,12 @@ export declare const snippetConversational: (model: ModelDataMinimal, accessToke
11
11
  }) => InferenceSnippet[];
12
12
  export declare const snippetZeroShotClassification: (model: ModelDataMinimal) => InferenceSnippet[];
13
13
  export declare const snippetZeroShotImageClassification: (model: ModelDataMinimal) => InferenceSnippet[];
14
- export declare const snippetBasic: (model: ModelDataMinimal) => InferenceSnippet[];
14
+ export declare const snippetBasic: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
15
15
  export declare const snippetFile: (model: ModelDataMinimal) => InferenceSnippet[];
16
- export declare const snippetTextToImage: (model: ModelDataMinimal, accessToken: string, provider: InferenceProvider) => InferenceSnippet[];
16
+ export declare const snippetTextToImage: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
17
17
  export declare const snippetTabular: (model: ModelDataMinimal) => InferenceSnippet[];
18
18
  export declare const snippetTextToAudio: (model: ModelDataMinimal) => InferenceSnippet[];
19
19
  export declare const snippetDocumentQuestionAnswering: (model: ModelDataMinimal) => InferenceSnippet[];
20
- export declare const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: InferenceProvider, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
21
- export declare function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: InferenceProvider, opts?: Record<string, unknown>): InferenceSnippet[];
20
+ export declare const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
21
+ export declare function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, opts?: Record<string, unknown>): InferenceSnippet[];
22
22
  //# sourceMappingURL=python.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../src/snippets/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,KAAK,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAG1F,OAAO,KAAK,EAAE,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AChC,gBAAgB,EAqDlB,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,gBAAgB,KAAG,gBAAgB,EAcxE,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,gBAAgB,KAAG,gBAAgB,EAuC5E,CAAC;AAEF,eAAO,MAAM,gCAAgC,UAAW,gBAAgB,KAAG,gBAAgB,EAiB1F,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CACnC,MAAM,CACL,YAAY,EACZ,CACC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,gBAAgB,EAAE,CACvB,CA8BD,CAAC;AAEF,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CA0BpB"}
@@ -1,6 +1,35 @@
1
- import { HF_HUB_INFERENCE_PROXY_TEMPLATE, openAIbaseUrl } from "../inference-providers.js";
1
+ import { openAIbaseUrl, } from "../inference-providers.js";
2
2
  import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
3
3
  import { getModelInputSnippet } from "./inputs.js";
4
+ const HFH_INFERENCE_CLIENT_METHODS = {
5
+ "audio-classification": "audio_classification",
6
+ "audio-to-audio": "audio_to_audio",
7
+ "automatic-speech-recognition": "automatic_speech_recognition",
8
+ "text-to-speech": "text_to_speech",
9
+ "image-classification": "image_classification",
10
+ "image-segmentation": "image_segmentation",
11
+ "image-to-image": "image_to_image",
12
+ "image-to-text": "image_to_text",
13
+ "object-detection": "object_detection",
14
+ "text-to-image": "text_to_image",
15
+ "text-to-video": "text_to_video",
16
+ "zero-shot-image-classification": "zero_shot_image_classification",
17
+ "document-question-answering": "document_question_answering",
18
+ "visual-question-answering": "visual_question_answering",
19
+ "feature-extraction": "feature_extraction",
20
+ "fill-mask": "fill_mask",
21
+ "question-answering": "question_answering",
22
+ "sentence-similarity": "sentence_similarity",
23
+ summarization: "summarization",
24
+ "table-question-answering": "table_question_answering",
25
+ "text-classification": "text_classification",
26
+ "text-generation": "text_generation",
27
+ "token-classification": "token_classification",
28
+ translation: "translation",
29
+ "zero-shot-classification": "zero_shot_classification",
30
+ "tabular-classification": "tabular_classification",
31
+ "tabular-regression": "tabular_regression",
32
+ };
4
33
  const snippetImportInferenceClient = (accessToken, provider) => `\
5
34
  from huggingface_hub import InferenceClient
6
35
 
@@ -34,7 +63,7 @@ messages = ${messagesStr}
34
63
  stream = client.chat.completions.create(
35
64
  model="${model.id}",
36
65
  messages=messages,
37
- ${configStr},
66
+ ${configStr}
38
67
  stream=True
39
68
  )
40
69
 
@@ -56,7 +85,7 @@ messages = ${messagesStr}
56
85
  stream = client.chat.completions.create(
57
86
  model="${model.id}",
58
87
  messages=messages,
59
- ${configStr},
88
+ ${configStr}
60
89
  stream=True
61
90
  )
62
91
 
@@ -143,8 +172,26 @@ output = query({
143
172
  },
144
173
  ];
145
174
  };
146
- export const snippetBasic = (model) => {
175
+ export const snippetBasic = (model, accessToken, provider) => {
147
176
  return [
177
+ ...(model.pipeline_tag && model.pipeline_tag in HFH_INFERENCE_CLIENT_METHODS
178
+ ? [
179
+ {
180
+ client: "huggingface_hub",
181
+ content: `\
182
+ ${snippetImportInferenceClient(accessToken, provider)}
183
+
184
+ result = client.${HFH_INFERENCE_CLIENT_METHODS[model.pipeline_tag]}(
185
+ model="${model.id}",
186
+ inputs=${getModelInputSnippet(model)},
187
+ provider="${provider}",
188
+ )
189
+
190
+ print(result)
191
+ `,
192
+ },
193
+ ]
194
+ : []),
148
195
  {
149
196
  client: "requests",
150
197
  content: `\
@@ -340,9 +387,6 @@ export function getPythonInferenceSnippet(model, accessToken, provider, opts) {
340
387
  const snippets = model.pipeline_tag && model.pipeline_tag in pythonSnippets
341
388
  ? pythonSnippets[model.pipeline_tag]?.(model, accessToken, provider) ?? []
342
389
  : [];
343
- const baseUrl = provider === "hf-inference"
344
- ? `https://api-inference.huggingface.co/models/${model.id}`
345
- : HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider);
346
390
  return snippets.map((snippet) => {
347
391
  return {
348
392
  ...snippet,
@@ -350,7 +394,7 @@ export function getPythonInferenceSnippet(model, accessToken, provider, opts) {
350
394
  ? `\
351
395
  import requests
352
396
 
353
- API_URL = "${baseUrl}"
397
+ API_URL = "${openAIbaseUrl(provider)}"
354
398
  headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
355
399
 
356
400
  ${snippet.content}`
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA4CpD,mBAAmB,qCAAqC,CAAC;AACzD,mBAAmB,6CAA6C,CAAC;AACjE,YAAY,EACX,mBAAmB,EACnB,0BAA0B,EAC1B,oBAAoB,EACpB,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,gCAAgC,EAChC,+BAA+B,GAC/B,MAAM,gCAAgC,CAAC;AACxC,mBAAmB,4CAA4C,CAAC;AAChE,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,0BAA0B,CAAC;AAC9C,YAAY,EACX,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,6BAA6B,GAC7B,MAAM,qCAAqC,CAAC;AAC7C,mBAAmB,+BAA+B,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC/G,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,iCAAiC,CAAC;AACrD,mBAAmB,iCAAiC,CAAC;AACrD,mBAAmB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-3d": ["diffusers"],
106
106
  "any-to-any": ["transformers"],
107
+ "visual-document-retrieval": ["transformers"],
107
108
  };
108
109
  /**
109
110
  * Return the whole TaskData object for a certain task.
@@ -130,6 +131,7 @@ export const TASKS_DATA = {
130
131
  "automatic-speech-recognition": getData("automatic-speech-recognition", automaticSpeechRecognition),
131
132
  "depth-estimation": getData("depth-estimation", depthEstimation),
132
133
  "document-question-answering": getData("document-question-answering", documentQuestionAnswering),
134
+ "visual-document-retrieval": getData("visual-document-retrieval", placeholder),
133
135
  "feature-extraction": getData("feature-extraction", featureExtraction),
134
136
  "fill-mask": getData("fill-mask", fillMask),
135
137
  "graph-ml": undefined,
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/tasks/text-generation/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAM,QAAQ,EAAE,cA2Hf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/tasks/text-generation/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAM,QAAQ,EAAE,cAyHf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -56,9 +56,7 @@ const taskData = {
56
56
  },
57
57
  ],
58
58
  models: [
59
- { description: "A text-generation model trained to follow instructions.",
60
- id: "google/gemma-2-2b-it",
61
- },
59
+ { description: "A text-generation model trained to follow instructions.", id: "google/gemma-2-2b-it" },
62
60
  {
63
61
  description: "Smaller variant of one of the most powerful models.",
64
62
  id: "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@huggingface/tasks",
3
3
  "packageManager": "pnpm@8.10.5",
4
- "version": "0.15.7",
4
+ "version": "0.15.9",
5
5
  "description": "List of ML tasks for huggingface.co/tasks",
6
6
  "repository": "https://github.com/huggingface/huggingface.js.git",
7
7
  "publishConfig": {
@@ -1,16 +1,25 @@
1
- export const INFERENCE_PROVIDERS = ["hf-inference", "fal-ai", "replicate", "sambanova", "together"] as const;
1
+ /// This list is for illustration purposes only.
2
+ /// in the `tasks` sub-package, we do not need actual strong typing of the inference providers.
3
+ const INFERENCE_PROVIDERS = [
4
+ "fal-ai",
5
+ "fireworks-ai",
6
+ "hf-inference",
7
+ "hyperbolic",
8
+ "replicate",
9
+ "sambanova",
10
+ "together",
11
+ ] as const;
2
12
 
3
- export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
13
+ export type SnippetInferenceProvider = (typeof INFERENCE_PROVIDERS)[number] | string;
4
14
 
5
- export const HF_HUB_INFERENCE_PROXY_TEMPLATE = `https://huggingface.co/api/inference-proxy/{{PROVIDER}}`;
15
+ export const HF_HUB_INFERENCE_PROXY_TEMPLATE = `https://router.huggingface.co/{{PROVIDER}}`;
6
16
 
7
17
  /**
8
18
  * URL to set as baseUrl in the OpenAI SDK.
9
19
  *
10
20
  * TODO(Expose this from HfInference in the future?)
11
21
  */
12
- export function openAIbaseUrl(provider: InferenceProvider): string {
13
- return provider === "hf-inference"
14
- ? "https://api-inference.huggingface.co/v1/"
15
- : HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider);
22
+ export function openAIbaseUrl(provider: SnippetInferenceProvider): string {
23
+ const url = HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider);
24
+ return provider === "hf-inference" ? `${url}/v1` : url;
16
25
  }
@@ -3,7 +3,7 @@ import type { PipelineType } from "./pipelines.js";
3
3
 
4
4
  /**
5
5
  * Mapping from library name to its supported tasks.
6
- * Inference API (serverless) should be disabled for all other (library, task) pairs beyond this mapping.
6
+ * HF-Inference API (serverless) should be disabled for all other (library, task) pairs beyond this mapping.
7
7
  * This mapping is partially generated automatically by "python-api-export-tasks" action in
8
8
  * huggingface/api-inference-community repo upon merge. For transformers, the mapping is manually
9
9
  * based on api-inference (hf_types.rs).
@@ -83,6 +83,20 @@ function get_prompt_from_diffusers_model(model: ModelData): string | undefined {
83
83
  }
84
84
  }
85
85
 
86
+ export const ben2 = (model: ModelData): string[] => [
87
+ `import requests
88
+ from PIL import Image
89
+ from ben2 import AutoModel
90
+
91
+ url = "https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg"
92
+ image = Image.open(requests.get(url, stream=True).raw)
93
+
94
+ model = AutoModel.from_pretrained("${model.id}")
95
+ model.to("cuda").eval()
96
+ foreground = model.inference(image)
97
+ `,
98
+ ];
99
+
86
100
  export const bertopic = (model: ModelData): string[] => [
87
101
  `from bertopic import BERTopic
88
102
 
@@ -443,7 +457,7 @@ const _keras_hub_causal_lm = (modelId: string): string => `
443
457
  import keras_hub
444
458
 
445
459
  # Load CausalLM model (optional: use half precision for inference)
446
- causal_lm = keras_hub.models.CausalLM.from_preset("${modelId}", dtype="bfloat16")
460
+ causal_lm = keras_hub.models.CausalLM.from_preset("hf://${modelId}", dtype="bfloat16")
447
461
  causal_lm.compile(sampler="greedy") # (optional) specify a sampler
448
462
 
449
463
  # Generate text
@@ -454,7 +468,7 @@ const _keras_hub_text_to_image = (modelId: string): string => `
454
468
  import keras_hub
455
469
 
456
470
  # Load TextToImage model (optional: use half precision for inference)
457
- text_to_image = keras_hub.models.TextToImage.from_preset("${modelId}", dtype="bfloat16")
471
+ text_to_image = keras_hub.models.TextToImage.from_preset("hf://${modelId}", dtype="bfloat16")
458
472
 
459
473
  # Generate images with a TextToImage model.
460
474
  text_to_image.generate("Astronaut in a jungle")
@@ -465,7 +479,7 @@ import keras_hub
465
479
 
466
480
  # Load TextClassifier model
467
481
  text_classifier = keras_hub.models.TextClassifier.from_preset(
468
- "${modelId}",
482
+ "hf://${modelId}",
469
483
  num_classes=2,
470
484
  )
471
485
  # Fine-tune
@@ -480,7 +494,7 @@ import keras
480
494
 
481
495
  # Load ImageClassifier model
482
496
  image_classifier = keras_hub.models.ImageClassifier.from_preset(
483
- "${modelId}",
497
+ "hf://${modelId}",
484
498
  num_classes=2,
485
499
  )
486
500
  # Fine-tune
@@ -503,14 +517,14 @@ const _keras_hub_task_without_example = (task: string, modelId: string): string
503
517
  import keras_hub
504
518
 
505
519
  # Create a ${task} model
506
- task = keras_hub.models.${task}.from_preset("${modelId}")
520
+ task = keras_hub.models.${task}.from_preset("hf://${modelId}")
507
521
  `;
508
522
 
509
523
  const _keras_hub_generic_backbone = (modelId: string): string => `
510
524
  import keras_hub
511
525
 
512
526
  # Create a Backbone model unspecialized for any task
513
- backbone = keras_hub.models.Backbone.from_preset("${modelId}")
527
+ backbone = keras_hub.models.Backbone.from_preset("hf://${modelId}")
514
528
  `;
515
529
 
516
530
  export const keras_hub = (model: ModelData): string[] => {
@@ -109,6 +109,13 @@ export const MODEL_LIBRARIES_UI_ELEMENTS = {
109
109
  countDownloads: `path_extension:"pth"`,
110
110
  snippets: snippets.audioseal,
111
111
  },
112
+ ben2: {
113
+ prettyLabel: "BEN2",
114
+ repoName: "BEN2",
115
+ repoUrl: "https://github.com/PramaLLC/BEN2",
116
+ snippets: snippets.ben2,
117
+ filter: false,
118
+ },
112
119
  bertopic: {
113
120
  prettyLabel: "BERTopic",
114
121
  repoName: "BERTopic",
package/src/pipelines.ts CHANGED
@@ -676,6 +676,12 @@ export const PIPELINE_DATA = {
676
676
  color: "red",
677
677
  hideInDatasets: true,
678
678
  },
679
+ "visual-document-retrieval": {
680
+ name: "Visual Document Retrieval",
681
+ modality: "multimodal",
682
+ color: "yellow",
683
+ hideInDatasets: true,
684
+ },
679
685
  "any-to-any": {
680
686
  name: "Any-to-Any",
681
687
  modality: "multimodal",
@@ -34,6 +34,6 @@ export function stringifyGenerationConfig(
34
34
  const quote = opts.attributeKeyQuotes ? `"` : "";
35
35
 
36
36
  return Object.entries(config)
37
- .map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val}`)
38
- .join(`,${opts.indent}`);
37
+ .map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val},`)
38
+ .join(`${opts.indent}`);
39
39
  }
@@ -1,4 +1,4 @@
1
- import { HF_HUB_INFERENCE_PROXY_TEMPLATE, type InferenceProvider } from "../inference-providers.js";
1
+ import { HF_HUB_INFERENCE_PROXY_TEMPLATE, type SnippetInferenceProvider } from "../inference-providers.js";
2
2
  import type { PipelineType } from "../pipelines.js";
3
3
  import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js";
4
4
  import { stringifyGenerationConfig, stringifyMessages } from "./common.js";
@@ -8,7 +8,7 @@ import type { InferenceSnippet, ModelDataMinimal } from "./types.js";
8
8
  export const snippetBasic = (
9
9
  model: ModelDataMinimal,
10
10
  accessToken: string,
11
- provider: InferenceProvider
11
+ provider: SnippetInferenceProvider
12
12
  ): InferenceSnippet[] => {
13
13
  if (provider !== "hf-inference") {
14
14
  return [];
@@ -17,7 +17,7 @@ export const snippetBasic = (
17
17
  {
18
18
  client: "curl",
19
19
  content: `\
20
- curl https://api-inference.huggingface.co/models/${model.id} \\
20
+ curl https://router.huggingface.co/hf-inference/models/${model.id} \\
21
21
  -X POST \\
22
22
  -d '{"inputs": ${getModelInputSnippet(model, true)}}' \\
23
23
  -H 'Content-Type: application/json' \\
@@ -29,7 +29,7 @@ curl https://api-inference.huggingface.co/models/${model.id} \\
29
29
  export const snippetTextGeneration = (
30
30
  model: ModelDataMinimal,
31
31
  accessToken: string,
32
- provider: InferenceProvider,
32
+ provider: SnippetInferenceProvider,
33
33
  opts?: {
34
34
  streaming?: boolean;
35
35
  messages?: ChatCompletionInputMessage[];
@@ -41,7 +41,7 @@ export const snippetTextGeneration = (
41
41
  if (model.tags.includes("conversational")) {
42
42
  const baseUrl =
43
43
  provider === "hf-inference"
44
- ? `https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions`
44
+ ? `https://router.huggingface.co/hf-inference/models/${model.id}/v1/chat/completions`
45
45
  : HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider) + "/v1/chat/completions";
46
46
 
47
47
  // Conversational model detected, so we display a code snippet that features the Messages API
@@ -63,15 +63,15 @@ export const snippetTextGeneration = (
63
63
  --data '{
64
64
  "model": "${model.id}",
65
65
  "messages": ${stringifyMessages(messages, {
66
- indent: "\t",
67
- attributeKeyQuotes: true,
68
- customContentEscaper: (str) => str.replace(/'/g, "'\\''"),
69
- })},
66
+ indent: "\t",
67
+ attributeKeyQuotes: true,
68
+ customContentEscaper: (str) => str.replace(/'/g, "'\\''"),
69
+ })},
70
70
  ${stringifyGenerationConfig(config, {
71
- indent: "\n ",
72
- attributeKeyQuotes: true,
73
- attributeValueConnector: ": ",
74
- })},
71
+ indent: "\n ",
72
+ attributeKeyQuotes: true,
73
+ attributeValueConnector: ": ",
74
+ })}
75
75
  "stream": ${!!streaming}
76
76
  }'`,
77
77
  },
@@ -84,7 +84,7 @@ export const snippetTextGeneration = (
84
84
  export const snippetZeroShotClassification = (
85
85
  model: ModelDataMinimal,
86
86
  accessToken: string,
87
- provider: InferenceProvider
87
+ provider: SnippetInferenceProvider
88
88
  ): InferenceSnippet[] => {
89
89
  if (provider !== "hf-inference") {
90
90
  return [];
@@ -92,7 +92,7 @@ export const snippetZeroShotClassification = (
92
92
  return [
93
93
  {
94
94
  client: "curl",
95
- content: `curl https://api-inference.huggingface.co/models/${model.id} \\
95
+ content: `curl https://router.huggingface.co/hf-inference/models/${model.id} \\
96
96
  -X POST \\
97
97
  -d '{"inputs": ${getModelInputSnippet(model, true)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}' \\
98
98
  -H 'Content-Type: application/json' \\
@@ -104,7 +104,7 @@ export const snippetZeroShotClassification = (
104
104
  export const snippetFile = (
105
105
  model: ModelDataMinimal,
106
106
  accessToken: string,
107
- provider: InferenceProvider
107
+ provider: SnippetInferenceProvider
108
108
  ): InferenceSnippet[] => {
109
109
  if (provider !== "hf-inference") {
110
110
  return [];
@@ -112,7 +112,7 @@ export const snippetFile = (
112
112
  return [
113
113
  {
114
114
  client: "curl",
115
- content: `curl https://api-inference.huggingface.co/models/${model.id} \\
115
+ content: `curl https://router.huggingface.co/hf-inference/models/${model.id} \\
116
116
  -X POST \\
117
117
  --data-binary '@${getModelInputSnippet(model, true, true)}' \\
118
118
  -H 'Authorization: Bearer ${accessToken || `{API_TOKEN}`}'`,
@@ -126,7 +126,7 @@ export const curlSnippets: Partial<
126
126
  (
127
127
  model: ModelDataMinimal,
128
128
  accessToken: string,
129
- provider: InferenceProvider,
129
+ provider: SnippetInferenceProvider,
130
130
  opts?: Record<string, unknown>
131
131
  ) => InferenceSnippet[]
132
132
  >
@@ -160,7 +160,7 @@ export const curlSnippets: Partial<
160
160
  export function getCurlInferenceSnippet(
161
161
  model: ModelDataMinimal,
162
162
  accessToken: string,
163
- provider: InferenceProvider,
163
+ provider: SnippetInferenceProvider,
164
164
  opts?: Record<string, unknown>
165
165
  ): InferenceSnippet[] {
166
166
  return model.pipeline_tag && model.pipeline_tag in curlSnippets