@huggingface/tasks 0.13.4 → 0.13.5

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 (49) hide show
  1. package/dist/commonjs/local-apps.d.ts.map +1 -1
  2. package/dist/commonjs/local-apps.js +40 -21
  3. package/dist/commonjs/local-apps.spec.d.ts +2 -0
  4. package/dist/commonjs/local-apps.spec.d.ts.map +1 -0
  5. package/dist/commonjs/local-apps.spec.js +114 -0
  6. package/dist/commonjs/model-libraries-snippets.d.ts.map +1 -1
  7. package/dist/commonjs/model-libraries-snippets.js +23 -12
  8. package/dist/commonjs/model-libraries-snippets.spec.d.ts +2 -0
  9. package/dist/commonjs/model-libraries-snippets.spec.d.ts.map +1 -0
  10. package/dist/commonjs/model-libraries-snippets.spec.js +51 -0
  11. package/dist/commonjs/tasks/audio-classification/inference.d.ts +3 -0
  12. package/dist/commonjs/tasks/audio-classification/inference.d.ts.map +1 -1
  13. package/dist/commonjs/tasks/image-classification/inference.d.ts +3 -0
  14. package/dist/commonjs/tasks/image-classification/inference.d.ts.map +1 -1
  15. package/dist/commonjs/tasks/text-classification/inference.d.ts +3 -0
  16. package/dist/commonjs/tasks/text-classification/inference.d.ts.map +1 -1
  17. package/dist/commonjs/tasks/video-classification/inference.d.ts +3 -0
  18. package/dist/commonjs/tasks/video-classification/inference.d.ts.map +1 -1
  19. package/dist/esm/local-apps.d.ts.map +1 -1
  20. package/dist/esm/local-apps.js +40 -21
  21. package/dist/esm/local-apps.spec.d.ts +2 -0
  22. package/dist/esm/local-apps.spec.d.ts.map +1 -0
  23. package/dist/esm/local-apps.spec.js +112 -0
  24. package/dist/esm/model-libraries-snippets.d.ts.map +1 -1
  25. package/dist/esm/model-libraries-snippets.js +23 -12
  26. package/dist/esm/model-libraries-snippets.spec.d.ts +2 -0
  27. package/dist/esm/model-libraries-snippets.spec.d.ts.map +1 -0
  28. package/dist/esm/model-libraries-snippets.spec.js +49 -0
  29. package/dist/esm/tasks/audio-classification/inference.d.ts +3 -0
  30. package/dist/esm/tasks/audio-classification/inference.d.ts.map +1 -1
  31. package/dist/esm/tasks/image-classification/inference.d.ts +3 -0
  32. package/dist/esm/tasks/image-classification/inference.d.ts.map +1 -1
  33. package/dist/esm/tasks/text-classification/inference.d.ts +3 -0
  34. package/dist/esm/tasks/text-classification/inference.d.ts.map +1 -1
  35. package/dist/esm/tasks/video-classification/inference.d.ts +3 -0
  36. package/dist/esm/tasks/video-classification/inference.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/local-apps.spec.ts +123 -0
  39. package/src/local-apps.ts +37 -18
  40. package/src/model-libraries-snippets.spec.ts +54 -0
  41. package/src/model-libraries-snippets.ts +24 -11
  42. package/src/tasks/audio-classification/inference.ts +3 -0
  43. package/src/tasks/audio-classification/spec/input.json +2 -1
  44. package/src/tasks/image-classification/inference.ts +3 -0
  45. package/src/tasks/image-classification/spec/input.json +2 -1
  46. package/src/tasks/text-classification/inference.ts +3 -0
  47. package/src/tasks/text-classification/spec/input.json +2 -1
  48. package/src/tasks/video-classification/inference.ts +3 -0
  49. package/src/tasks/video-classification/spec/input.json +2 -1
@@ -0,0 +1,112 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { LOCAL_APPS } from "./local-apps.js";
3
+ describe("local-apps", () => {
4
+ it("llama.cpp conversational", async () => {
5
+ const { snippet: snippetFunc } = LOCAL_APPS["llama.cpp"];
6
+ const model = {
7
+ id: "bartowski/Llama-3.2-3B-Instruct-GGUF",
8
+ tags: ["conversational"],
9
+ inference: "",
10
+ };
11
+ const snippet = snippetFunc(model);
12
+ expect(snippet[0].content).toEqual(`# Load and run the model:
13
+ llama-cli \\
14
+ --hf-repo "bartowski/Llama-3.2-3B-Instruct-GGUF" \\
15
+ --hf-file {{GGUF_FILE}} \\
16
+ -p "You are a helpful assistant" \\
17
+ --conversation`);
18
+ });
19
+ it("llama.cpp non-conversational", async () => {
20
+ const { snippet: snippetFunc } = LOCAL_APPS["llama.cpp"];
21
+ const model = {
22
+ id: "mlabonne/gemma-2b-GGUF",
23
+ tags: [],
24
+ inference: "",
25
+ };
26
+ const snippet = snippetFunc(model);
27
+ expect(snippet[0].content).toEqual(`# Load and run the model:
28
+ llama-cli \\
29
+ --hf-repo "mlabonne/gemma-2b-GGUF" \\
30
+ --hf-file {{GGUF_FILE}} \\
31
+ -p "Once upon a time,"`);
32
+ });
33
+ it("vLLM conversational llm", async () => {
34
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
35
+ const model = {
36
+ id: "meta-llama/Llama-3.2-3B-Instruct",
37
+ pipeline_tag: "text-generation",
38
+ tags: ["conversational"],
39
+ inference: "",
40
+ };
41
+ const snippet = snippetFunc(model);
42
+ expect(snippet[0].content.join("\n")).toEqual(`# Load and run the model:
43
+ vllm serve "meta-llama/Llama-3.2-3B-Instruct"
44
+ # Call the server using curl:
45
+ curl -X POST "http://localhost:8000/v1/chat/completions" \\
46
+ -H "Content-Type: application/json" \\
47
+ --data '{
48
+ "model": "meta-llama/Llama-3.2-3B-Instruct",
49
+ "messages": [
50
+ {
51
+ "role": "user",
52
+ "content": "What is the capital of France?"
53
+ }
54
+ ]
55
+ }'`);
56
+ });
57
+ it("vLLM non-conversational llm", async () => {
58
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
59
+ const model = {
60
+ id: "meta-llama/Llama-3.2-3B",
61
+ tags: [""],
62
+ inference: "",
63
+ };
64
+ const snippet = snippetFunc(model);
65
+ expect(snippet[0].content.join("\n")).toEqual(`# Load and run the model:
66
+ vllm serve "meta-llama/Llama-3.2-3B"
67
+ # Call the server using curl:
68
+ curl -X POST "http://localhost:8000/v1/completions" \\
69
+ -H "Content-Type: application/json" \\
70
+ --data '{
71
+ "model": "meta-llama/Llama-3.2-3B",
72
+ "prompt": "Once upon a time,",
73
+ "max_tokens": 512,
74
+ "temperature": 0.5
75
+ }'`);
76
+ });
77
+ it("vLLM conversational vlm", async () => {
78
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
79
+ const model = {
80
+ id: "meta-llama/Llama-3.2-11B-Vision-Instruct",
81
+ pipeline_tag: "image-text-to-text",
82
+ tags: ["conversational"],
83
+ inference: "",
84
+ };
85
+ const snippet = snippetFunc(model);
86
+ expect(snippet[0].content.join("\n")).toEqual(`# Load and run the model:
87
+ vllm serve "meta-llama/Llama-3.2-11B-Vision-Instruct"
88
+ # Call the server using curl:
89
+ curl -X POST "http://localhost:8000/v1/chat/completions" \\
90
+ -H "Content-Type: application/json" \\
91
+ --data '{
92
+ "model": "meta-llama/Llama-3.2-11B-Vision-Instruct",
93
+ "messages": [
94
+ {
95
+ "role": "user",
96
+ "content": [
97
+ {
98
+ "type": "text",
99
+ "text": "Describe this image in one sentence."
100
+ },
101
+ {
102
+ "type": "image_url",
103
+ "image_url": {
104
+ "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ ]
110
+ }'`);
111
+ });
112
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"model-libraries-snippets.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAejD,eAAO,MAAM,QAAQ,UAAW,SAAS,KAAG,MAAM,EAKjD,CAAC;AAkBF,eAAO,MAAM,QAAQ,UAAW,SAAS,KAAG,MAAM,EAKjD,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,SAAS,KAAG,MAAM,EAIjD,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,SAAS,KAAG,MAAM,EAkBlD,CAAC;AAaF,eAAO,MAAM,QAAQ,UAAW,SAAS,KAAG,MAAM,EAIjD,CAAC;AAEF,eAAO,MAAM,KAAK,UAAW,SAAS,KAAG,MAAM,EAI9C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,SAAS,KAAG,MAAM,EA6C1D,CAA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,KAAG,MAAM,EAIjD,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,SAAS,KAAG,MAAM,EAInD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,MAAM,EAYhC,CAAC;AAEF,eAAO,MAAM,OAAO,UAAW,SAAS,KAAG,MAAM,EAOhD,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,SAAS,KAAG,MAAM,EAYjD,CAAC;AAEF,eAAO,MAAM,GAAG,UAAW,SAAS,KAAG,MAAM,EAK5C,CAAC;AAEF,eAAO,MAAM,KAAK,UAAW,SAAS,KAAG,MAAM,EAI9C,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,SAAS,KAAG,MAAM,EAIlD,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,SAAS,KAAG,MAAM,EAQ7C,CAAC;AAEF,eAAO,MAAM,IAAI,UAAW,SAAS,KAAG,MAAM,EAI7C,CAAC;AAEF,eAAO,MAAM,MAAM,UAAW,SAAS,KAAG,MAAM,EAI/C,CAAC;AA6BF,eAAO,MAAM,UAAU,UAAW,SAAS,KAAG,MAAM,EAUnD,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,MAAM,EAYnC,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,SAAS,KAAG,MAAM,EAKvD,CAAC;AAEF,eAAO,MAAM,KAAK,UAAW,SAAS,KAAG,MAAM,EAI9C,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import { LIBRARY_TASK_MAPPING } from "./library-to-tasks.js";
2
+ import { getModelInputSnippet } from "./snippets/inputs.js";
3
+ import { stringifyMessages } from "./snippets/common.js";
2
4
  const TAG_CUSTOM_CODE = "custom_code";
3
5
  function nameWithoutNamespace(modelId) {
4
6
  const splitted = modelId.split("/");
@@ -374,23 +376,32 @@ model = keras_hub.models.CausalLM.from_preset("hf://${model.id}", dtype="bfloat1
374
376
  # full list here: https://keras.io/api/keras_hub/models/#api-documentation
375
377
  `,
376
378
  ];
377
- export const llama_cpp_python = (model) => [
378
- `from llama_cpp import Llama
379
+ export const llama_cpp_python = (model) => {
380
+ const snippets = [
381
+ `from llama_cpp import Llama
379
382
 
380
383
  llm = Llama.from_pretrained(
381
384
  repo_id="${model.id}",
382
385
  filename="{{GGUF_FILE}}",
383
386
  )
384
-
385
- llm.create_chat_completion(
386
- messages = [
387
- {
388
- "role": "user",
389
- "content": "What is the capital of France?"
390
- }
391
- ]
392
- )`,
393
- ];
387
+ `,
388
+ ];
389
+ if (model.tags.includes("conversational")) {
390
+ const messages = getModelInputSnippet(model);
391
+ snippets.push(`llm.create_chat_completion(
392
+ messages = ${stringifyMessages(messages, { attributeKeyQuotes: true, indent: "\t" })}
393
+ )`);
394
+ }
395
+ else {
396
+ snippets.push(`output = llm(
397
+ "Once upon a time,",
398
+ max_tokens=512,
399
+ echo=True
400
+ )
401
+ print(output)`);
402
+ }
403
+ return snippets;
404
+ };
394
405
  export const tf_keras = (model) => [
395
406
  `# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
396
407
  # See https://github.com/keras-team/tf-keras for more details.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=model-libraries-snippets.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-libraries-snippets.spec.d.ts","sourceRoot":"","sources":["../../src/model-libraries-snippets.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,49 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { llama_cpp_python } from "./model-libraries-snippets.js";
3
+ describe("model-libraries-snippets", () => {
4
+ it("llama_cpp_python conversational", async () => {
5
+ const model = {
6
+ id: "bartowski/Llama-3.2-3B-Instruct-GGUF",
7
+ pipeline_tag: "text-generation",
8
+ tags: ["conversational"],
9
+ inference: "",
10
+ };
11
+ const snippet = llama_cpp_python(model);
12
+ expect(snippet.join("\n")).toEqual(`from llama_cpp import Llama
13
+
14
+ llm = Llama.from_pretrained(
15
+ repo_id="bartowski/Llama-3.2-3B-Instruct-GGUF",
16
+ filename="{{GGUF_FILE}}",
17
+ )
18
+
19
+ llm.create_chat_completion(
20
+ messages = [
21
+ {
22
+ "role": "user",
23
+ "content": "What is the capital of France?"
24
+ }
25
+ ]
26
+ )`);
27
+ });
28
+ it("llama_cpp_python non-conversational", async () => {
29
+ const model = {
30
+ id: "mlabonne/gemma-2b-GGUF",
31
+ tags: [""],
32
+ inference: "",
33
+ };
34
+ const snippet = llama_cpp_python(model);
35
+ expect(snippet.join("\n")).toEqual(`from llama_cpp import Llama
36
+
37
+ llm = Llama.from_pretrained(
38
+ repo_id="mlabonne/gemma-2b-GGUF",
39
+ filename="{{GGUF_FILE}}",
40
+ )
41
+
42
+ output = llm(
43
+ "Once upon a time,",
44
+ max_tokens=512,
45
+ echo=True
46
+ )
47
+ print(output)`);
48
+ });
49
+ });
@@ -24,6 +24,9 @@ export interface AudioClassificationInput {
24
24
  * Additional inference parameters for Audio Classification
25
25
  */
26
26
  export interface AudioClassificationParameters {
27
+ /**
28
+ * The function to apply to the model outputs in order to retrieve the scores.
29
+ */
27
30
  function_to_apply?: ClassificationOutputTransform;
28
31
  /**
29
32
  * When specified, limits the output to the top K most probable classes.
@@ -1 +1 @@
1
- {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/audio-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/audio-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
@@ -24,6 +24,9 @@ export interface ImageClassificationInput {
24
24
  * Additional inference parameters for Image Classification
25
25
  */
26
26
  export interface ImageClassificationParameters {
27
+ /**
28
+ * The function to apply to the model outputs in order to retrieve the scores.
29
+ */
27
30
  function_to_apply?: ClassificationOutputTransform;
28
31
  /**
29
32
  * When specified, limits the output to the top K most probable classes.
@@ -1 +1 @@
1
- {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/image-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/image-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
@@ -23,6 +23,9 @@ export interface TextClassificationInput {
23
23
  * Additional inference parameters for Text Classification
24
24
  */
25
25
  export interface TextClassificationParameters {
26
+ /**
27
+ * The function to apply to the model outputs in order to retrieve the scores.
28
+ */
26
29
  function_to_apply?: ClassificationOutputTransform;
27
30
  /**
28
31
  * When specified, limits the output to the top K most probable classes.
@@ -1 +1 @@
1
- {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/text-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,4BAA4B,CAAC;IAC1C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC5C,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,wBAAwB,GAAG,+BAA+B,EAAE,CAAC;AACzE;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC/C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/text-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,4BAA4B,CAAC;IAC1C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC5C;;OAEG;IACH,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,wBAAwB,GAAG,+BAA+B,EAAE,CAAC;AACzE;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC/C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
@@ -27,6 +27,9 @@ export interface VideoClassificationParameters {
27
27
  * The sampling rate used to select frames from the video.
28
28
  */
29
29
  frame_sampling_rate?: number;
30
+ /**
31
+ * The function to apply to the model outputs in order to retrieve the scores.
32
+ */
30
33
  function_to_apply?: ClassificationOutputTransform;
31
34
  /**
32
35
  * The number of sampled frames to consider for classification.
@@ -1 +1 @@
1
- {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/video-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../../src/tasks/video-classification/inference.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,6BAA6B,CAAC;IAC3C,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAC7C;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,iBAAiB,CAAC,EAAE,6BAA6B,CAAC;IAClD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AACD;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,gCAAgC,EAAE,CAAC;AAC3E;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B"}
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.13.4",
4
+ "version": "0.13.5",
5
5
  "description": "List of ML tasks for huggingface.co/tasks",
6
6
  "repository": "https://github.com/huggingface/huggingface.js.git",
7
7
  "publishConfig": {
@@ -0,0 +1,123 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { LOCAL_APPS } from "./local-apps.js";
3
+ import type { ModelData } from "./model-data.js";
4
+
5
+ describe("local-apps", () => {
6
+ it("llama.cpp conversational", async () => {
7
+ const { snippet: snippetFunc } = LOCAL_APPS["llama.cpp"];
8
+ const model: ModelData = {
9
+ id: "bartowski/Llama-3.2-3B-Instruct-GGUF",
10
+ tags: ["conversational"],
11
+ inference: "",
12
+ };
13
+ const snippet = snippetFunc(model);
14
+
15
+ expect(snippet[0].content).toEqual(`# Load and run the model:
16
+ llama-cli \\
17
+ --hf-repo "bartowski/Llama-3.2-3B-Instruct-GGUF" \\
18
+ --hf-file {{GGUF_FILE}} \\
19
+ -p "You are a helpful assistant" \\
20
+ --conversation`);
21
+ });
22
+
23
+ it("llama.cpp non-conversational", async () => {
24
+ const { snippet: snippetFunc } = LOCAL_APPS["llama.cpp"];
25
+ const model: ModelData = {
26
+ id: "mlabonne/gemma-2b-GGUF",
27
+ tags: [],
28
+ inference: "",
29
+ };
30
+ const snippet = snippetFunc(model);
31
+
32
+ expect(snippet[0].content).toEqual(`# Load and run the model:
33
+ llama-cli \\
34
+ --hf-repo "mlabonne/gemma-2b-GGUF" \\
35
+ --hf-file {{GGUF_FILE}} \\
36
+ -p "Once upon a time,"`);
37
+ });
38
+
39
+ it("vLLM conversational llm", async () => {
40
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
41
+ const model: ModelData = {
42
+ id: "meta-llama/Llama-3.2-3B-Instruct",
43
+ pipeline_tag: "text-generation",
44
+ tags: ["conversational"],
45
+ inference: "",
46
+ };
47
+ const snippet = snippetFunc(model);
48
+
49
+ expect((snippet[0].content as string[]).join("\n")).toEqual(`# Load and run the model:
50
+ vllm serve "meta-llama/Llama-3.2-3B-Instruct"
51
+ # Call the server using curl:
52
+ curl -X POST "http://localhost:8000/v1/chat/completions" \\
53
+ -H "Content-Type: application/json" \\
54
+ --data '{
55
+ "model": "meta-llama/Llama-3.2-3B-Instruct",
56
+ "messages": [
57
+ {
58
+ "role": "user",
59
+ "content": "What is the capital of France?"
60
+ }
61
+ ]
62
+ }'`);
63
+ });
64
+
65
+ it("vLLM non-conversational llm", async () => {
66
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
67
+ const model: ModelData = {
68
+ id: "meta-llama/Llama-3.2-3B",
69
+ tags: [""],
70
+ inference: "",
71
+ };
72
+ const snippet = snippetFunc(model);
73
+
74
+ expect((snippet[0].content as string[]).join("\n")).toEqual(`# Load and run the model:
75
+ vllm serve "meta-llama/Llama-3.2-3B"
76
+ # Call the server using curl:
77
+ curl -X POST "http://localhost:8000/v1/completions" \\
78
+ -H "Content-Type: application/json" \\
79
+ --data '{
80
+ "model": "meta-llama/Llama-3.2-3B",
81
+ "prompt": "Once upon a time,",
82
+ "max_tokens": 512,
83
+ "temperature": 0.5
84
+ }'`);
85
+ });
86
+
87
+ it("vLLM conversational vlm", async () => {
88
+ const { snippet: snippetFunc } = LOCAL_APPS["vllm"];
89
+ const model: ModelData = {
90
+ id: "meta-llama/Llama-3.2-11B-Vision-Instruct",
91
+ pipeline_tag: "image-text-to-text",
92
+ tags: ["conversational"],
93
+ inference: "",
94
+ };
95
+ const snippet = snippetFunc(model);
96
+
97
+ expect((snippet[0].content as string[]).join("\n")).toEqual(`# Load and run the model:
98
+ vllm serve "meta-llama/Llama-3.2-11B-Vision-Instruct"
99
+ # Call the server using curl:
100
+ curl -X POST "http://localhost:8000/v1/chat/completions" \\
101
+ -H "Content-Type: application/json" \\
102
+ --data '{
103
+ "model": "meta-llama/Llama-3.2-11B-Vision-Instruct",
104
+ "messages": [
105
+ {
106
+ "role": "user",
107
+ "content": [
108
+ {
109
+ "type": "text",
110
+ "text": "Describe this image in one sentence."
111
+ },
112
+ {
113
+ "type": "image_url",
114
+ "image_url": {
115
+ "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
116
+ }
117
+ }
118
+ ]
119
+ }
120
+ ]
121
+ }'`);
122
+ });
123
+ });
package/src/local-apps.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { parseGGUFQuantLabel } from "./gguf.js";
2
2
  import type { ModelData } from "./model-data.js";
3
3
  import type { PipelineType } from "./pipelines.js";
4
+ import { stringifyMessages } from "./snippets/common.js";
5
+ import { getModelInputSnippet } from "./snippets/inputs.js";
6
+ import type { ChatCompletionInputMessage } from "./tasks/index.js";
4
7
 
5
8
  export interface LocalAppSnippet {
6
9
  /**
@@ -92,15 +95,20 @@ function isMlxModel(model: ModelData) {
92
95
  }
93
96
 
94
97
  const snippetLlamacpp = (model: ModelData, filepath?: string): LocalAppSnippet[] => {
95
- const command = (binary: string) =>
96
- [
98
+ const command = (binary: string) => {
99
+ const snippet = [
97
100
  "# Load and run the model:",
98
101
  `${binary} \\`,
99
102
  ` --hf-repo "${model.id}" \\`,
100
103
  ` --hf-file ${filepath ?? "{{GGUF_FILE}}"} \\`,
101
- ' -p "You are a helpful assistant" \\',
102
- " --conversation",
103
- ].join("\n");
104
+ ` -p "${model.tags.includes("conversational") ? "You are a helpful assistant" : "Once upon a time,"}"`,
105
+ ];
106
+ if (model.tags.includes("conversational")) {
107
+ snippet[snippet.length - 1] += " \\";
108
+ snippet.push(" --conversation");
109
+ }
110
+ return snippet.join("\n");
111
+ };
104
112
  return [
105
113
  {
106
114
  title: "Install from brew",
@@ -178,22 +186,33 @@ const snippetLocalAI = (model: ModelData, filepath?: string): LocalAppSnippet[]
178
186
  };
179
187
 
180
188
  const snippetVllm = (model: ModelData): LocalAppSnippet[] => {
181
- const runCommand = [
182
- "# Call the server using curl:",
183
- `curl -X POST "http://localhost:8000/v1/chat/completions" \\`,
184
- ` -H "Content-Type: application/json" \\`,
185
- ` --data '{`,
186
- ` "model": "${model.id}",`,
187
- ` "messages": [`,
188
- ` {"role": "user", "content": "Hello!"}`,
189
- ` ]`,
190
- ` }'`,
191
- ];
189
+ const messages = getModelInputSnippet(model) as ChatCompletionInputMessage[];
190
+ const runCommandInstruct = `# Call the server using curl:
191
+ curl -X POST "http://localhost:8000/v1/chat/completions" \\
192
+ -H "Content-Type: application/json" \\
193
+ --data '{
194
+ "model": "${model.id}",
195
+ "messages": ${stringifyMessages(messages, {
196
+ indent: "\t\t",
197
+ attributeKeyQuotes: true,
198
+ customContentEscaper: (str) => str.replace(/'/g, "'\\''"),
199
+ })}
200
+ }'`;
201
+ const runCommandNonInstruct = `# Call the server using curl:
202
+ curl -X POST "http://localhost:8000/v1/completions" \\
203
+ -H "Content-Type: application/json" \\
204
+ --data '{
205
+ "model": "${model.id}",
206
+ "prompt": "Once upon a time,",
207
+ "max_tokens": 512,
208
+ "temperature": 0.5
209
+ }'`;
210
+ const runCommand = model.tags.includes("conversational") ? runCommandInstruct : runCommandNonInstruct;
192
211
  return [
193
212
  {
194
213
  title: "Install from pip",
195
214
  setup: ["# Install vLLM from pip:", "pip install vllm"].join("\n"),
196
- content: [`# Load and run the model:\nvllm serve "${model.id}"`, runCommand.join("\n")],
215
+ content: [`# Load and run the model:\nvllm serve "${model.id}"`, runCommand],
197
216
  },
198
217
  {
199
218
  title: "Use Docker images",
@@ -210,7 +229,7 @@ const snippetVllm = (model: ModelData): LocalAppSnippet[] => {
210
229
  ].join("\n"),
211
230
  content: [
212
231
  `# Load and run the model:\ndocker exec -it my_vllm_container bash -c "vllm serve ${model.id}"`,
213
- runCommand.join("\n"),
232
+ runCommand,
214
233
  ],
215
234
  },
216
235
  ];
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { ModelData } from "./model-data.js";
3
+ import { llama_cpp_python } from "./model-libraries-snippets.js";
4
+
5
+ describe("model-libraries-snippets", () => {
6
+ it("llama_cpp_python conversational", async () => {
7
+ const model: ModelData = {
8
+ id: "bartowski/Llama-3.2-3B-Instruct-GGUF",
9
+ pipeline_tag: "text-generation",
10
+ tags: ["conversational"],
11
+ inference: "",
12
+ };
13
+ const snippet = llama_cpp_python(model);
14
+
15
+ expect(snippet.join("\n")).toEqual(`from llama_cpp import Llama
16
+
17
+ llm = Llama.from_pretrained(
18
+ repo_id="bartowski/Llama-3.2-3B-Instruct-GGUF",
19
+ filename="{{GGUF_FILE}}",
20
+ )
21
+
22
+ llm.create_chat_completion(
23
+ messages = [
24
+ {
25
+ "role": "user",
26
+ "content": "What is the capital of France?"
27
+ }
28
+ ]
29
+ )`);
30
+ });
31
+
32
+ it("llama_cpp_python non-conversational", async () => {
33
+ const model: ModelData = {
34
+ id: "mlabonne/gemma-2b-GGUF",
35
+ tags: [""],
36
+ inference: "",
37
+ };
38
+ const snippet = llama_cpp_python(model);
39
+
40
+ expect(snippet.join("\n")).toEqual(`from llama_cpp import Llama
41
+
42
+ llm = Llama.from_pretrained(
43
+ repo_id="mlabonne/gemma-2b-GGUF",
44
+ filename="{{GGUF_FILE}}",
45
+ )
46
+
47
+ output = llm(
48
+ "Once upon a time,",
49
+ max_tokens=512,
50
+ echo=True
51
+ )
52
+ print(output)`);
53
+ });
54
+ });
@@ -1,6 +1,9 @@
1
1
  import type { ModelData } from "./model-data.js";
2
2
  import type { WidgetExampleTextInput, WidgetExampleSentenceSimilarityInput } from "./widget-example.js";
3
3
  import { LIBRARY_TASK_MAPPING } from "./library-to-tasks.js";
4
+ import { getModelInputSnippet } from "./snippets/inputs.js";
5
+ import type { ChatCompletionInputMessage } from "./tasks/index.js";
6
+ import { stringifyMessages } from "./snippets/common.js";
4
7
 
5
8
  const TAG_CUSTOM_CODE = "custom_code";
6
9
 
@@ -418,23 +421,33 @@ model = keras_hub.models.CausalLM.from_preset("hf://${model.id}", dtype="bfloat1
418
421
  `,
419
422
  ];
420
423
 
421
- export const llama_cpp_python = (model: ModelData): string[] => [
422
- `from llama_cpp import Llama
424
+ export const llama_cpp_python = (model: ModelData): string[] => {
425
+ const snippets = [
426
+ `from llama_cpp import Llama
423
427
 
424
428
  llm = Llama.from_pretrained(
425
429
  repo_id="${model.id}",
426
430
  filename="{{GGUF_FILE}}",
427
431
  )
432
+ `,
433
+ ];
428
434
 
429
- llm.create_chat_completion(
430
- messages = [
431
- {
432
- "role": "user",
433
- "content": "What is the capital of France?"
434
- }
435
- ]
436
- )`,
437
- ];
435
+ if (model.tags.includes("conversational")) {
436
+ const messages = getModelInputSnippet(model) as ChatCompletionInputMessage[];
437
+ snippets.push(`llm.create_chat_completion(
438
+ messages = ${stringifyMessages(messages, { attributeKeyQuotes: true, indent: "\t" })}
439
+ )`);
440
+ } else {
441
+ snippets.push(`output = llm(
442
+ "Once upon a time,",
443
+ max_tokens=512,
444
+ echo=True
445
+ )
446
+ print(output)`);
447
+ }
448
+
449
+ return snippets;
450
+ };
438
451
 
439
452
  export const tf_keras = (model: ModelData): string[] => [
440
453
  `# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
@@ -24,6 +24,9 @@ export interface AudioClassificationInput {
24
24
  * Additional inference parameters for Audio Classification
25
25
  */
26
26
  export interface AudioClassificationParameters {
27
+ /**
28
+ * The function to apply to the model outputs in order to retrieve the scores.
29
+ */
27
30
  function_to_apply?: ClassificationOutputTransform;
28
31
  /**
29
32
  * When specified, limits the output to the top K most probable classes.