@huggingface/inference 2.1.1 → 2.1.3-test

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
@@ -116,7 +116,7 @@ function makeRequestOptions(args, options) {
116
116
  // src/tasks/custom/request.ts
117
117
  async function request(args, options) {
118
118
  const { url, info } = makeRequestOptions(args, options);
119
- const response = await (options?.custom_fetch ?? fetch)(url, info);
119
+ const response = await (options?.fetch ?? fetch)(url, info);
120
120
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
121
121
  return request(args, {
122
122
  ...options,
@@ -240,7 +240,7 @@ function newMessage() {
240
240
  // src/tasks/custom/streamingRequest.ts
241
241
  async function* streamingRequest(args, options) {
242
242
  const { url, info } = makeRequestOptions({ ...args, stream: true }, options);
243
- const response = await (options?.custom_fetch ?? fetch)(url, info);
243
+ const response = await (options?.fetch ?? fetch)(url, info);
244
244
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
245
245
  return streamingRequest(args, {
246
246
  ...options,
@@ -543,7 +543,7 @@ async function zeroShotClassification(args, options) {
543
543
  return res;
544
544
  }
545
545
 
546
- // ../shared/src/base64FromBytes.ts
546
+ // src/utils/base64FromBytes.ts
547
547
  function base64FromBytes(arr) {
548
548
  if (globalThis.Buffer) {
549
549
  return globalThis.Buffer.from(arr).toString("base64");
package/dist/index.mjs CHANGED
@@ -71,7 +71,7 @@ function makeRequestOptions(args, options) {
71
71
  // src/tasks/custom/request.ts
72
72
  async function request(args, options) {
73
73
  const { url, info } = makeRequestOptions(args, options);
74
- const response = await (options?.custom_fetch ?? fetch)(url, info);
74
+ const response = await (options?.fetch ?? fetch)(url, info);
75
75
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
76
76
  return request(args, {
77
77
  ...options,
@@ -195,7 +195,7 @@ function newMessage() {
195
195
  // src/tasks/custom/streamingRequest.ts
196
196
  async function* streamingRequest(args, options) {
197
197
  const { url, info } = makeRequestOptions({ ...args, stream: true }, options);
198
- const response = await (options?.custom_fetch ?? fetch)(url, info);
198
+ const response = await (options?.fetch ?? fetch)(url, info);
199
199
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
200
200
  return streamingRequest(args, {
201
201
  ...options,
@@ -498,7 +498,7 @@ async function zeroShotClassification(args, options) {
498
498
  return res;
499
499
  }
500
500
 
501
- // ../shared/src/base64FromBytes.ts
501
+ // src/utils/base64FromBytes.ts
502
502
  function base64FromBytes(arr) {
503
503
  if (globalThis.Buffer) {
504
504
  return globalThis.Buffer.from(arr).toString("base64");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "2.1.1",
3
+ "version": "2.1.3-test",
4
4
  "license": "MIT",
5
5
  "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript wrapper for the Hugging Face Inference API",
@@ -12,7 +12,7 @@ export async function request<T>(
12
12
  }
13
13
  ): Promise<T> {
14
14
  const { url, info } = makeRequestOptions(args, options);
15
- const response = await (options?.custom_fetch ?? fetch)(url, info);
15
+ const response = await (options?.fetch ?? fetch)(url, info);
16
16
 
17
17
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
18
18
  return request(args, {
@@ -14,7 +14,7 @@ export async function* streamingRequest<T>(
14
14
  }
15
15
  ): AsyncGenerator<T> {
16
16
  const { url, info } = makeRequestOptions({ ...args, stream: true }, options);
17
- const response = await (options?.custom_fetch ?? fetch)(url, info);
17
+ const response = await (options?.fetch ?? fetch)(url, info);
18
18
 
19
19
  if (options?.retry_on_error !== false && response.status === 503 && !options?.wait_for_model) {
20
20
  return streamingRequest(args, {
@@ -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 "../../../../shared/src/base64FromBytes";
5
+ import { base64FromBytes } from "../../utils/base64FromBytes";
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 "../../../../shared/src/base64FromBytes";
4
+ import { base64FromBytes } from "../../utils/base64FromBytes";
5
5
 
6
6
  export type VisualQuestionAnsweringArgs = BaseArgs & {
7
7
  inputs: {
package/src/types.ts CHANGED
@@ -23,7 +23,7 @@ export interface Options {
23
23
  /**
24
24
  * Custom fetch function to use instead of the default one, for example to use a proxy or edit headers.
25
25
  */
26
- custom_fetch?: typeof fetch;
26
+ fetch?: typeof fetch;
27
27
  }
28
28
 
29
29
  export interface BaseArgs {
@@ -0,0 +1,11 @@
1
+ export function base64FromBytes(arr: Uint8Array): string {
2
+ if (globalThis.Buffer) {
3
+ return globalThis.Buffer.from(arr).toString("base64");
4
+ } else {
5
+ const bin: string[] = [];
6
+ arr.forEach((byte) => {
7
+ bin.push(String.fromCharCode(byte));
8
+ });
9
+ return globalThis.btoa(bin.join(""));
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
2
+
3
+ const isWebWorker =
4
+ typeof self === "object" && self.constructor && self.constructor.name === "DedicatedWorkerGlobalScope";
5
+
6
+ export const isBackend = !isBrowser && !isWebWorker;
@@ -0,0 +1,3 @@
1
+ import { isBackend } from "./isBackend";
2
+
3
+ export const isFrontend = !isBackend;