@huggingface/inference 4.3.0 → 4.3.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AAiCjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CACjB,EACD,OAAO,EAAE;IACR,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAwB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CAyB5B"}
1
+ {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AAiCjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CACjB,EACD,OAAO,EAAE;IACR,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAwB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CA0B5B"}
@@ -108,6 +108,7 @@ async function resolveProvider(provider, modelId, endpointUrl) {
108
108
  }
109
109
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
110
110
  provider = mappings[0]?.provider;
111
+ console.log("Auto selected provider:", provider);
111
112
  }
112
113
  if (!provider) {
113
114
  throw new errors_js_1.InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "4.3.0";
1
+ export declare const PACKAGE_VERSION = "4.3.1";
2
2
  export declare const PACKAGE_NAME = "@huggingface/inference";
3
3
  //# sourceMappingURL=package.d.ts.map
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
4
4
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
5
- exports.PACKAGE_VERSION = "4.3.0";
5
+ exports.PACKAGE_VERSION = "4.3.1";
6
6
  exports.PACKAGE_NAME = "@huggingface/inference";
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAMvE,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC;IACR,cAAc,EAAE;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KAClB,CAAC;CACF;AAaD;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EACnC,IAAI,EAAE,WAAW,EACjB,cAAc,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,EACpD,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAwE7B;AAED;;GAEG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAC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AC,CAuJnB"}
@@ -5,13 +5,23 @@ exports.innerStreamingRequest = innerStreamingRequest;
5
5
  const makeRequestOptions_js_1 = require("../lib/makeRequestOptions.js");
6
6
  const parse_js_1 = require("../vendor/fetch-event-source/parse.js");
7
7
  const errors_js_1 = require("../errors.js");
8
- function requestArgsToJson(args) {
9
- // Convert the entire args object to a JSON-serializable format
10
- const argsWithData = args;
11
- return JSON.parse(JSON.stringify({
12
- ...argsWithData,
13
- data: argsWithData.data ? "[Blob or ArrayBuffer]" : null,
14
- }));
8
+ function bodyToJson(body) {
9
+ let data = null;
10
+ if (body instanceof Blob || body instanceof ArrayBuffer) {
11
+ data = "[Blob or ArrayBuffer]";
12
+ }
13
+ else if (typeof body === "string") {
14
+ try {
15
+ data = JSON.parse(body);
16
+ }
17
+ catch {
18
+ data = body;
19
+ }
20
+ }
21
+ if (data.accessToken) {
22
+ data.accessToken = "[REDACTED]";
23
+ }
24
+ return data;
15
25
  }
16
26
  /**
17
27
  * Primitive to make custom calls to the inference provider
@@ -32,7 +42,7 @@ async function innerRequest(args, providerHelper, options) {
32
42
  url,
33
43
  method: info.method ?? "GET",
34
44
  headers: info.headers,
35
- body: requestArgsToJson(args),
45
+ body: bodyToJson(info.body),
36
46
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
37
47
  }
38
48
  if (typeof output.error === "string" || typeof output.detail === "string" || typeof output.message === "string") {
@@ -40,7 +50,7 @@ async function innerRequest(args, providerHelper, options) {
40
50
  url,
41
51
  method: info.method ?? "GET",
42
52
  headers: info.headers,
43
- body: requestArgsToJson(args),
53
+ body: bodyToJson(info.body),
44
54
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
45
55
  }
46
56
  else {
@@ -48,7 +58,7 @@ async function innerRequest(args, providerHelper, options) {
48
58
  url,
49
59
  method: info.method ?? "GET",
50
60
  headers: info.headers,
51
- body: requestArgsToJson(args),
61
+ body: bodyToJson(info.body),
52
62
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
53
63
  }
54
64
  }
@@ -57,7 +67,7 @@ async function innerRequest(args, providerHelper, options) {
57
67
  url,
58
68
  method: info.method ?? "GET",
59
69
  headers: info.headers,
60
- body: requestArgsToJson(args),
70
+ body: bodyToJson(info.body),
61
71
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" });
62
72
  }
63
73
  if (response.headers.get("Content-Type")?.startsWith("application/json")) {
@@ -84,7 +94,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
84
94
  url,
85
95
  method: info.method ?? "GET",
86
96
  headers: info.headers,
87
- body: requestArgsToJson(args),
97
+ body: bodyToJson(info.body),
88
98
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
89
99
  }
90
100
  if (typeof output.error === "string") {
@@ -92,7 +102,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
92
102
  url,
93
103
  method: info.method ?? "GET",
94
104
  headers: info.headers,
95
- body: requestArgsToJson(args),
105
+ body: bodyToJson(info.body),
96
106
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
97
107
  }
98
108
  if (output.error && "message" in output.error && typeof output.error.message === "string") {
@@ -101,7 +111,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
101
111
  url,
102
112
  method: info.method ?? "GET",
103
113
  headers: info.headers,
104
- body: requestArgsToJson(args),
114
+ body: bodyToJson(info.body),
105
115
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
106
116
  }
107
117
  // Sambanova errors
@@ -110,7 +120,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
110
120
  url,
111
121
  method: info.method ?? "GET",
112
122
  headers: info.headers,
113
- body: requestArgsToJson(args),
123
+ body: bodyToJson(info.body),
114
124
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
115
125
  }
116
126
  }
@@ -118,7 +128,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
118
128
  url,
119
129
  method: info.method ?? "GET",
120
130
  headers: info.headers,
121
- body: requestArgsToJson(args),
131
+ body: bodyToJson(info.body),
122
132
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
123
133
  }
124
134
  if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
@@ -127,7 +137,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
127
137
  url,
128
138
  method: info.method ?? "GET",
129
139
  headers: info.headers,
130
- body: requestArgsToJson(args),
140
+ body: bodyToJson(info.body),
131
141
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
132
142
  }
133
143
  if (!response.body) {
@@ -166,7 +176,7 @@ async function* innerStreamingRequest(args, providerHelper, options) {
166
176
  url,
167
177
  method: info.method ?? "GET",
168
178
  headers: info.headers,
169
- body: requestArgsToJson(args),
179
+ body: bodyToJson(info.body),
170
180
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data });
171
181
  }
172
182
  yield data;
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AAiCjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM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CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAwB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CA0B5B"}
@@ -102,6 +102,7 @@ export async function resolveProvider(provider, modelId, endpointUrl) {
102
102
  }
103
103
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
104
104
  provider = mappings[0]?.provider;
105
+ console.log("Auto selected provider:", provider);
105
106
  }
106
107
  if (!provider) {
107
108
  throw new InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "4.3.0";
1
+ export declare const PACKAGE_VERSION = "4.3.1";
2
2
  export declare const PACKAGE_NAME = "@huggingface/inference";
3
3
  //# sourceMappingURL=package.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
2
- export const PACKAGE_VERSION = "4.3.0";
2
+ export const PACKAGE_VERSION = "4.3.1";
3
3
  export const PACKAGE_NAME = "@huggingface/inference";
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAMvE,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC;IACR,cAAc,EAAE;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC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pC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAwE7B;AAED;;GAEG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAC7C,IAAI,EAAE,WAAW,EACjB,cAAc,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,EACpD,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,cAAc,CAAC,CAAC,CAAC,CAuJnB"}
@@ -1,13 +1,23 @@
1
1
  import { makeRequestOptions } from "../lib/makeRequestOptions.js";
2
2
  import { getLines, getMessages } from "../vendor/fetch-event-source/parse.js";
3
3
  import { InferenceClientProviderApiError } from "../errors.js";
4
- function requestArgsToJson(args) {
5
- // Convert the entire args object to a JSON-serializable format
6
- const argsWithData = args;
7
- return JSON.parse(JSON.stringify({
8
- ...argsWithData,
9
- data: argsWithData.data ? "[Blob or ArrayBuffer]" : null,
10
- }));
4
+ function bodyToJson(body) {
5
+ let data = null;
6
+ if (body instanceof Blob || body instanceof ArrayBuffer) {
7
+ data = "[Blob or ArrayBuffer]";
8
+ }
9
+ else if (typeof body === "string") {
10
+ try {
11
+ data = JSON.parse(body);
12
+ }
13
+ catch {
14
+ data = body;
15
+ }
16
+ }
17
+ if (data.accessToken) {
18
+ data.accessToken = "[REDACTED]";
19
+ }
20
+ return data;
11
21
  }
12
22
  /**
13
23
  * Primitive to make custom calls to the inference provider
@@ -28,7 +38,7 @@ export async function innerRequest(args, providerHelper, options) {
28
38
  url,
29
39
  method: info.method ?? "GET",
30
40
  headers: info.headers,
31
- body: requestArgsToJson(args),
41
+ body: bodyToJson(info.body),
32
42
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
33
43
  }
34
44
  if (typeof output.error === "string" || typeof output.detail === "string" || typeof output.message === "string") {
@@ -36,7 +46,7 @@ export async function innerRequest(args, providerHelper, options) {
36
46
  url,
37
47
  method: info.method ?? "GET",
38
48
  headers: info.headers,
39
- body: requestArgsToJson(args),
49
+ body: bodyToJson(info.body),
40
50
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
41
51
  }
42
52
  else {
@@ -44,7 +54,7 @@ export async function innerRequest(args, providerHelper, options) {
44
54
  url,
45
55
  method: info.method ?? "GET",
46
56
  headers: info.headers,
47
- body: requestArgsToJson(args),
57
+ body: bodyToJson(info.body),
48
58
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
49
59
  }
50
60
  }
@@ -53,7 +63,7 @@ export async function innerRequest(args, providerHelper, options) {
53
63
  url,
54
64
  method: info.method ?? "GET",
55
65
  headers: info.headers,
56
- body: requestArgsToJson(args),
66
+ body: bodyToJson(info.body),
57
67
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" });
58
68
  }
59
69
  if (response.headers.get("Content-Type")?.startsWith("application/json")) {
@@ -80,7 +90,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
80
90
  url,
81
91
  method: info.method ?? "GET",
82
92
  headers: info.headers,
83
- body: requestArgsToJson(args),
93
+ body: bodyToJson(info.body),
84
94
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
85
95
  }
86
96
  if (typeof output.error === "string") {
@@ -88,7 +98,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
88
98
  url,
89
99
  method: info.method ?? "GET",
90
100
  headers: info.headers,
91
- body: requestArgsToJson(args),
101
+ body: bodyToJson(info.body),
92
102
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
93
103
  }
94
104
  if (output.error && "message" in output.error && typeof output.error.message === "string") {
@@ -97,7 +107,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
97
107
  url,
98
108
  method: info.method ?? "GET",
99
109
  headers: info.headers,
100
- body: requestArgsToJson(args),
110
+ body: bodyToJson(info.body),
101
111
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
102
112
  }
103
113
  // Sambanova errors
@@ -106,7 +116,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
106
116
  url,
107
117
  method: info.method ?? "GET",
108
118
  headers: info.headers,
109
- body: requestArgsToJson(args),
119
+ body: bodyToJson(info.body),
110
120
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
111
121
  }
112
122
  }
@@ -114,7 +124,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
114
124
  url,
115
125
  method: info.method ?? "GET",
116
126
  headers: info.headers,
117
- body: requestArgsToJson(args),
127
+ body: bodyToJson(info.body),
118
128
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
119
129
  }
120
130
  if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
@@ -123,7 +133,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
123
133
  url,
124
134
  method: info.method ?? "GET",
125
135
  headers: info.headers,
126
- body: requestArgsToJson(args),
136
+ body: bodyToJson(info.body),
127
137
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
128
138
  }
129
139
  if (!response.body) {
@@ -162,7 +172,7 @@ export async function* innerStreamingRequest(args, providerHelper, options) {
162
172
  url,
163
173
  method: info.method ?? "GET",
164
174
  headers: info.headers,
165
- body: requestArgsToJson(args),
175
+ body: bodyToJson(info.body),
166
176
  }, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data });
167
177
  }
168
178
  yield data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Hugging Face and Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript client for the Hugging Face Inference Providers and Inference Endpoints",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "type": "module",
42
42
  "dependencies": {
43
- "@huggingface/tasks": "^0.19.21",
44
- "@huggingface/jinja": "^0.5.0"
43
+ "@huggingface/jinja": "^0.5.0",
44
+ "@huggingface/tasks": "^0.19.22"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "18.13.0"
@@ -160,6 +160,7 @@ export async function resolveProvider(
160
160
  }
161
161
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
162
162
  provider = mappings[0]?.provider as InferenceProvider | undefined;
163
+ console.log("Auto selected provider:", provider);
163
164
  }
164
165
  if (!provider) {
165
166
  throw new InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
package/src/package.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
2
- export const PACKAGE_VERSION = "4.3.0";
2
+ export const PACKAGE_VERSION = "4.3.1";
3
3
  export const PACKAGE_NAME = "@huggingface/inference";
@@ -14,15 +14,21 @@ export interface ResponseWrapper<T> {
14
14
  };
15
15
  }
16
16
 
17
- function requestArgsToJson(args: RequestArgs): JsonObject {
18
- // Convert the entire args object to a JSON-serializable format
19
- const argsWithData = args as RequestArgs & { data?: Blob | ArrayBuffer };
20
- return JSON.parse(
21
- JSON.stringify({
22
- ...argsWithData,
23
- data: argsWithData.data ? "[Blob or ArrayBuffer]" : null,
24
- })
25
- ) as JsonObject;
17
+ function bodyToJson(body?: BodyInit | null): JsonObject {
18
+ let data = null;
19
+ if (body instanceof Blob || body instanceof ArrayBuffer) {
20
+ data = "[Blob or ArrayBuffer]";
21
+ } else if (typeof body === "string") {
22
+ try {
23
+ data = JSON.parse(body);
24
+ } catch {
25
+ data = body;
26
+ }
27
+ }
28
+ if (data.accessToken) {
29
+ data.accessToken = "[REDACTED]";
30
+ }
31
+ return data as JsonObject;
26
32
  }
27
33
 
28
34
  /**
@@ -60,7 +66,7 @@ export async function innerRequest<T>(
60
66
  url,
61
67
  method: info.method ?? "GET",
62
68
  headers: info.headers as Record<string, string>,
63
- body: requestArgsToJson(args),
69
+ body: bodyToJson(info.body),
64
70
  },
65
71
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
66
72
  );
@@ -72,7 +78,7 @@ export async function innerRequest<T>(
72
78
  url,
73
79
  method: info.method ?? "GET",
74
80
  headers: info.headers as Record<string, string>,
75
- body: requestArgsToJson(args),
81
+ body: bodyToJson(info.body),
76
82
  },
77
83
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
78
84
  );
@@ -83,7 +89,7 @@ export async function innerRequest<T>(
83
89
  url,
84
90
  method: info.method ?? "GET",
85
91
  headers: info.headers as Record<string, string>,
86
- body: requestArgsToJson(args),
92
+ body: bodyToJson(info.body),
87
93
  },
88
94
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
89
95
  );
@@ -96,7 +102,7 @@ export async function innerRequest<T>(
96
102
  url,
97
103
  method: info.method ?? "GET",
98
104
  headers: info.headers as Record<string, string>,
99
- body: requestArgsToJson(args),
105
+ body: bodyToJson(info.body),
100
106
  },
101
107
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" }
102
108
  );
@@ -142,7 +148,7 @@ export async function* innerStreamingRequest<T>(
142
148
  url,
143
149
  method: info.method ?? "GET",
144
150
  headers: info.headers as Record<string, string>,
145
- body: requestArgsToJson(args),
151
+ body: bodyToJson(info.body),
146
152
  },
147
153
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
148
154
  );
@@ -154,7 +160,7 @@ export async function* innerStreamingRequest<T>(
154
160
  url,
155
161
  method: info.method ?? "GET",
156
162
  headers: info.headers as Record<string, string>,
157
- body: requestArgsToJson(args),
163
+ body: bodyToJson(info.body),
158
164
  },
159
165
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
160
166
  );
@@ -167,7 +173,7 @@ export async function* innerStreamingRequest<T>(
167
173
  url,
168
174
  method: info.method ?? "GET",
169
175
  headers: info.headers as Record<string, string>,
170
- body: requestArgsToJson(args),
176
+ body: bodyToJson(info.body),
171
177
  },
172
178
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
173
179
  );
@@ -180,7 +186,7 @@ export async function* innerStreamingRequest<T>(
180
186
  url,
181
187
  method: info.method ?? "GET",
182
188
  headers: info.headers as Record<string, string>,
183
- body: requestArgsToJson(args),
189
+ body: bodyToJson(info.body),
184
190
  },
185
191
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
186
192
  );
@@ -193,7 +199,7 @@ export async function* innerStreamingRequest<T>(
193
199
  url,
194
200
  method: info.method ?? "GET",
195
201
  headers: info.headers as Record<string, string>,
196
- body: requestArgsToJson(args),
202
+ body: bodyToJson(info.body),
197
203
  },
198
204
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
199
205
  );
@@ -206,7 +212,7 @@ export async function* innerStreamingRequest<T>(
206
212
  url,
207
213
  method: info.method ?? "GET",
208
214
  headers: info.headers as Record<string, string>,
209
- body: requestArgsToJson(args),
215
+ body: bodyToJson(info.body),
210
216
  },
211
217
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
212
218
  );
@@ -261,7 +267,7 @@ export async function* innerStreamingRequest<T>(
261
267
  url,
262
268
  method: info.method ?? "GET",
263
269
  headers: info.headers as Record<string, string>,
264
- body: requestArgsToJson(args),
270
+ body: bodyToJson(info.body),
265
271
  },
266
272
  { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data }
267
273
  );