@huggingface/inference 2.2.0 → 2.2.2

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/README.md CHANGED
@@ -188,6 +188,22 @@ await hf.documentQuestionAnswering({
188
188
  }
189
189
  })
190
190
 
191
+ // Tabular
192
+
193
+ await hf.tabularRegression({
194
+ model: "scikit-learn/Fish-Weight",
195
+ inputs: {
196
+ data: {
197
+ "Height":["11.52", "12.48", "12.3778"],
198
+ "Length1":["23.2", "24", "23.9"],
199
+ "Length2":["25.4", "26.3", "26.5"],
200
+ "Length3":["30", "31.2", "31.1"],
201
+ "Species":["Bream", "Bream", "Bream"],
202
+ "Width":["4.02", "4.3056", "4.6961"]
203
+ },
204
+ },
205
+ })
206
+
191
207
  // Custom call, for models with custom parameters / outputs
192
208
  await hf.request({
193
209
  model: 'my-custom-model',
@@ -222,7 +238,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
222
238
  - [x] Question answering
223
239
  - [x] Table question answering
224
240
  - [x] Text classification
225
- - [x] Text generation
241
+ - [x] Text generation - [demo](https://huggingface.co/spaces/huggingfacejs/streaming-text-generation)
226
242
  - [x] Text2Text generation
227
243
  - [x] Token classification
228
244
  - [x] Named entity recognition
@@ -243,11 +259,14 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
243
259
  - [x] Object detection
244
260
  - [x] Image segmentation
245
261
  - [x] Text to image
246
- - [x] Image to text
262
+ - [x] Image to text - [demo](https://huggingface.co/spaces/huggingfacejs/image-to-text)
247
263
 
248
264
  ### Multimodal
249
- - [x] Document question answering
250
- - [x] Visual question answering
265
+ - [x] Document question answering - [demo](https://huggingface.co/spaces/huggingfacejs/doc-vis-qa)
266
+ - [x] Visual question answering - [demo](https://huggingface.co/spaces/huggingfacejs/doc-vis-qa)
267
+
268
+ ### Tabular
269
+ - [x] Tabular regression
251
270
 
252
271
  ## Tree-shaking
253
272
 
package/dist/index.js CHANGED
@@ -38,6 +38,7 @@ __export(src_exports, {
38
38
  streamingRequest: () => streamingRequest,
39
39
  summarization: () => summarization,
40
40
  tableQuestionAnswering: () => tableQuestionAnswering,
41
+ tabularRegression: () => tabularRegression,
41
42
  textClassification: () => textClassification,
42
43
  textGeneration: () => textGeneration,
43
44
  textGenerationStream: () => textGenerationStream,
@@ -69,6 +70,7 @@ __export(tasks_exports, {
69
70
  streamingRequest: () => streamingRequest,
70
71
  summarization: () => summarization,
71
72
  tableQuestionAnswering: () => tableQuestionAnswering,
73
+ tabularRegression: () => tabularRegression,
72
74
  textClassification: () => textClassification,
73
75
  textGeneration: () => textGeneration,
74
76
  textGenerationStream: () => textGenerationStream,
@@ -559,7 +561,7 @@ async function zeroShotClassification(args, options) {
559
561
  return res;
560
562
  }
561
563
 
562
- // src/utils/base64FromBytes.ts
564
+ // ../shared/src/base64FromBytes.ts
563
565
  function base64FromBytes(arr) {
564
566
  if (globalThis.Buffer) {
565
567
  return globalThis.Buffer.from(arr).toString("base64");
@@ -572,6 +574,10 @@ function base64FromBytes(arr) {
572
574
  }
573
575
  }
574
576
 
577
+ // ../shared/src/isBackend.ts
578
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
579
+ var isWebWorker = typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
580
+
575
581
  // src/tasks/multimodal/documentQuestionAnswering.ts
576
582
  async function documentQuestionAnswering(args, options) {
577
583
  const reqArgs = {
@@ -610,6 +616,16 @@ async function visualQuestionAnswering(args, options) {
610
616
  return res;
611
617
  }
612
618
 
619
+ // src/tasks/tabular/tabularRegression.ts
620
+ async function tabularRegression(args, options) {
621
+ const res = await request(args, options);
622
+ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
623
+ if (!isValidOutput) {
624
+ throw new InferenceOutputError("Expected number[]");
625
+ }
626
+ return res;
627
+ }
628
+
613
629
  // src/HfInference.ts
614
630
  var HfInference = class {
615
631
  accessToken;
@@ -669,6 +685,7 @@ var HfInferenceEndpoint = class {
669
685
  streamingRequest,
670
686
  summarization,
671
687
  tableQuestionAnswering,
688
+ tabularRegression,
672
689
  textClassification,
673
690
  textGeneration,
674
691
  textGenerationStream,
package/dist/index.mjs CHANGED
@@ -23,6 +23,7 @@ __export(tasks_exports, {
23
23
  streamingRequest: () => streamingRequest,
24
24
  summarization: () => summarization,
25
25
  tableQuestionAnswering: () => tableQuestionAnswering,
26
+ tabularRegression: () => tabularRegression,
26
27
  textClassification: () => textClassification,
27
28
  textGeneration: () => textGeneration,
28
29
  textGenerationStream: () => textGenerationStream,
@@ -513,7 +514,7 @@ async function zeroShotClassification(args, options) {
513
514
  return res;
514
515
  }
515
516
 
516
- // src/utils/base64FromBytes.ts
517
+ // ../shared/src/base64FromBytes.ts
517
518
  function base64FromBytes(arr) {
518
519
  if (globalThis.Buffer) {
519
520
  return globalThis.Buffer.from(arr).toString("base64");
@@ -526,6 +527,10 @@ function base64FromBytes(arr) {
526
527
  }
527
528
  }
528
529
 
530
+ // ../shared/src/isBackend.ts
531
+ var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
532
+ var isWebWorker = typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
533
+
529
534
  // src/tasks/multimodal/documentQuestionAnswering.ts
530
535
  async function documentQuestionAnswering(args, options) {
531
536
  const reqArgs = {
@@ -564,6 +569,16 @@ async function visualQuestionAnswering(args, options) {
564
569
  return res;
565
570
  }
566
571
 
572
+ // src/tasks/tabular/tabularRegression.ts
573
+ async function tabularRegression(args, options) {
574
+ const res = await request(args, options);
575
+ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
576
+ if (!isValidOutput) {
577
+ throw new InferenceOutputError("Expected number[]");
578
+ }
579
+ return res;
580
+ }
581
+
567
582
  // src/HfInference.ts
568
583
  var HfInference = class {
569
584
  accessToken;
@@ -622,6 +637,7 @@ export {
622
637
  streamingRequest,
623
638
  summarization,
624
639
  tableQuestionAnswering,
640
+ tabularRegression,
625
641
  textClassification,
626
642
  textGeneration,
627
643
  textGenerationStream,
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "@huggingface/shared",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "main": "src/index.ts",
6
+ "source": "src/index.ts",
7
+ "types": "./src/index.ts"
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './base64FromBytes';
2
+ export * from './isBackend';
3
+ export * from './isFrontend';
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "esModuleInterop": true,
4
+ "noEmit": false,
5
+ "module": "ESNext",
6
+ "target": "ESNext",
7
+ "moduleResolution": "Node",
8
+ "noImplicitAny": true,
9
+ "strict": true,
10
+ "strictNullChecks": true,
11
+ "skipLibCheck": true,
12
+ "composite": true
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "license": "MIT",
5
5
  "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript wrapper for the Hugging Face Inference API",
@@ -40,8 +40,12 @@
40
40
  "@types/node": "18.13.0",
41
41
  "typescript": "^5.0.4",
42
42
  "vite": "^4.1.4",
43
- "vitest": "^0.29.8"
43
+ "vitest": "^0.29.8",
44
+ "@huggingface/shared": "1.0.0"
44
45
  },
46
+ "bundledDependencies": [
47
+ "@huggingface/shared"
48
+ ],
45
49
  "resolutions": {},
46
50
  "scripts": {
47
51
  "build": "tsup src/index.ts --format cjs,esm --clean",
@@ -49,6 +53,7 @@
49
53
  "lint:check": "eslint --ext .cjs,.ts .",
50
54
  "format": "prettier --write .",
51
55
  "format:check": "prettier --check .",
56
+ "preversion": "pnpm --filter doc-internal run fix-cdn-versions && git add ../../README.md",
52
57
  "test": "vitest run --config vitest.config.ts",
53
58
  "test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest.config.ts",
54
59
  "type-check": "tsc"
@@ -7,7 +7,7 @@ export * from "./audio/audioClassification";
7
7
  export * from "./audio/automaticSpeechRecognition";
8
8
  export * from "./audio/textToSpeech";
9
9
 
10
- // Commputer Vision tasks
10
+ // Computer Vision tasks
11
11
  export * from "./cv/imageClassification";
12
12
  export * from "./cv/imageSegmentation";
13
13
  export * from "./cv/imageToText";
@@ -32,3 +32,6 @@ export * from "./nlp/zeroShotClassification";
32
32
  // Multimodal tasks
33
33
  export * from "./multimodal/documentQuestionAnswering";
34
34
  export * from "./multimodal/visualQuestionAnswering";
35
+
36
+ // Tabular tasks
37
+ export * from "./tabular/tabularRegression";
@@ -2,7 +2,7 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";
2
2
  import type { BaseArgs, Options } from "../../types";
3
3
  import { request } from "../custom/request";
4
4
  import type { RequestArgs } from "../../types";
5
- import { base64FromBytes } from "../../utils/base64FromBytes";
5
+ import { base64FromBytes } from "@huggingface/shared";
6
6
  import { toArray } from "../../utils/toArray";
7
7
 
8
8
  export type DocumentQuestionAnsweringArgs = BaseArgs & {
@@ -1,7 +1,7 @@
1
1
  import { InferenceOutputError } from "../../lib/InferenceOutputError";
2
2
  import type { BaseArgs, Options, RequestArgs } from "../../types";
3
3
  import { request } from "../custom/request";
4
- import { base64FromBytes } from "../../utils/base64FromBytes";
4
+ import { base64FromBytes } from "@huggingface/shared";
5
5
 
6
6
  export type VisualQuestionAnsweringArgs = BaseArgs & {
7
7
  inputs: {
@@ -0,0 +1,34 @@
1
+ import { InferenceOutputError } from "../../lib/InferenceOutputError";
2
+ import type { BaseArgs, Options } from "../../types";
3
+ import { request } from "../custom/request";
4
+
5
+ export type TabularRegressionArgs = BaseArgs & {
6
+ inputs: {
7
+ /**
8
+ * A table of data represented as a dict of list where entries are headers and the lists are all the values, all lists must have the same size.
9
+ */
10
+ data: Record<string, string[]>;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * a list of predicted values for each row
16
+ */
17
+ export type TabularRegressionOutput = number[];
18
+
19
+ /**
20
+ * Predicts target value for a given set of features in tabular form.
21
+ * Typically, you will want to train a regression model on your training data and use it with your new data of the same format.
22
+ * Example model: scikit-learn/Fish-Weight
23
+ */
24
+ export async function tabularRegression(
25
+ args: TabularRegressionArgs,
26
+ options?: Options
27
+ ): Promise<TabularRegressionOutput> {
28
+ const res = await request<TabularRegressionOutput>(args, options);
29
+ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");
30
+ if (!isValidOutput) {
31
+ throw new InferenceOutputError("Expected number[]");
32
+ }
33
+ return res;
34
+ }