@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.
- package/dist/commonjs/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/commonjs/lib/getInferenceProviderMapping.js +1 -0
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/utils/request.d.ts.map +1 -1
- package/dist/commonjs/utils/request.js +28 -18
- package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/esm/lib/getInferenceProviderMapping.js +1 -0
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/utils/request.d.ts.map +1 -1
- package/dist/esm/utils/request.js +28 -18
- package/package.json +3 -3
- package/src/lib/getInferenceProviderMapping.ts +1 -0
- package/src/package.ts +1 -1
- package/src/utils/request.ts +26 -20
|
@@ -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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AE,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}.`);
|
package/dist/commonjs/package.js
CHANGED
|
@@ -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.
|
|
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;
|
|
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;AAmBD;;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,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"}
|
|
@@ -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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,O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CAAqC,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"}
|
|
@@ -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}.`);
|
package/dist/esm/package.d.ts
CHANGED
package/dist/esm/package.js
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.
|
|
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;KAClB,CAAC;CACF;
|
|
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;AAmBD;;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,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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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.
|
|
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/
|
|
44
|
-
"@huggingface/
|
|
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.
|
|
2
|
+
export const PACKAGE_VERSION = "4.3.1";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
package/src/utils/request.ts
CHANGED
|
@@ -14,15 +14,21 @@ export interface ResponseWrapper<T> {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
data
|
|
24
|
-
}
|
|
25
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
270
|
+
body: bodyToJson(info.body),
|
|
265
271
|
},
|
|
266
272
|
{ requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data }
|
|
267
273
|
);
|