@huggingface/inference 2.0.0-rc1 → 2.0.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/index.js CHANGED
@@ -96,7 +96,7 @@ function makeRequestOptions(args, options) {
96
96
  headers["X-Load-Model"] = "0";
97
97
  }
98
98
  }
99
- const url = /^http(s?):/.test(model) ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
99
+ const url = /^http(s?):/.test(model) || model.startsWith("/") ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
100
100
  const info = {
101
101
  headers,
102
102
  method: "POST",
package/dist/index.mjs CHANGED
@@ -53,7 +53,7 @@ function makeRequestOptions(args, options) {
53
53
  headers["X-Load-Model"] = "0";
54
54
  }
55
55
  }
56
- const url = /^http(s?):/.test(model) ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
56
+ const url = /^http(s?):/.test(model) || model.startsWith("/") ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
57
57
  const info = {
58
58
  headers,
59
59
  method: "POST",
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",
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
  });
@@ -38,7 +38,7 @@ export function makeRequestOptions(
38
38
  }
39
39
  }
40
40
 
41
- const url = /^http(s?):/.test(model) ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
41
+ const url = /^http(s?):/.test(model) || model.startsWith("/") ? model : `${HF_INFERENCE_API_BASE_URL}${model}`;
42
42
  const info: RequestInit = {
43
43
  headers,
44
44
  method: "POST",
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;