@huggingface/inference 2.0.0-rc1 → 2.0.0-rc2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "2.0.0rc1",
3
+ "version": "2.0.0-rc2",
4
4
  "license": "MIT",
5
5
  "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript wrapper for the Hugging Face Inference API",
@@ -1,18 +1,19 @@
1
1
  import * as tasks from "./tasks";
2
2
  import type { Options, RequestArgs } from "./types";
3
+ import type { DistributiveOmit } from "./utils/distributive-omit";
3
4
 
4
5
  type Task = typeof tasks;
5
6
 
6
7
  type TaskWithNoAccessToken = {
7
8
  [key in keyof Task]: (
8
- args: Omit<Parameters<Task[key]>[0], "accessToken">,
9
+ args: DistributiveOmit<Parameters<Task[key]>[0], "accessToken">,
9
10
  options?: Parameters<Task[key]>[1]
10
11
  ) => ReturnType<Task[key]>;
11
12
  };
12
13
 
13
14
  type TaskWithNoAccessTokenNoModel = {
14
15
  [key in keyof Task]: (
15
- args: Omit<Parameters<Task[key]>[0], "accessToken" | "model">,
16
+ args: DistributiveOmit<Parameters<Task[key]>[0], "accessToken" | "model">,
16
17
  options?: Parameters<Task[key]>[1]
17
18
  ) => ReturnType<Task[key]>;
18
19
  };
@@ -51,7 +52,7 @@ export class HfInferenceEndpoint {
51
52
  for (const [name, fn] of Object.entries(tasks)) {
52
53
  Object.defineProperty(this, name, {
53
54
  enumerable: false,
54
- value: (params: Omit<RequestArgs, "model">, options: Options) =>
55
+ value: (params: RequestArgs, options: Options) =>
55
56
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
57
  fn({ ...params, accessToken, model: endpointUrl } as any, { ...defaultOptions, ...options }),
57
58
  });
package/src/types.ts CHANGED
@@ -36,7 +36,7 @@ export interface BaseArgs {
36
36
  }
37
37
 
38
38
  export type RequestArgs = BaseArgs &
39
- ({ data?: Blob | ArrayBuffer } | { inputs: unknown }) & {
39
+ ({ data: Blob | ArrayBuffer } | { inputs: unknown }) & {
40
40
  parameters?: Record<string, unknown>;
41
41
  accessToken?: string;
42
42
  };
@@ -0,0 +1,15 @@
1
+ // https://dev.to/safareli/pick-omit-and-union-types-in-typescript-4nd9
2
+ // https://github.com/microsoft/TypeScript/issues/28339#issuecomment-467393437
3
+ /**
4
+ * This allows omitting keys from objects inside unions, without merging the individual components of the union.
5
+ */
6
+
7
+ type Keys<T> = keyof T;
8
+ type DistributiveKeys<T> = T extends unknown ? Keys<T> : never;
9
+ type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
10
+
11
+ export type DistributiveOmit<T, K> = T extends unknown
12
+ ? keyof Omit_<T, K> extends never
13
+ ? never
14
+ : { [P in keyof Omit_<T, K>]: Omit_<T, K>[P] }
15
+ : never;