@huggingface/inference 3.14.0 → 4.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/README.md +104 -1
- package/dist/commonjs/errors.d.ts +46 -0
- package/dist/commonjs/errors.d.ts.map +1 -0
- package/dist/commonjs/errors.js +70 -0
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +2 -3
- package/dist/commonjs/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/commonjs/lib/getInferenceProviderMapping.js +27 -16
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +5 -3
- package/dist/commonjs/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/commonjs/lib/makeRequestOptions.js +12 -11
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.d.ts.map +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/commonjs/providers/black-forest-labs.js +4 -4
- package/dist/commonjs/providers/fal-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/fal-ai.js +29 -17
- package/dist/commonjs/providers/featherless-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/featherless-ai.js +10 -4
- package/dist/commonjs/providers/hf-inference.d.ts.map +1 -1
- package/dist/commonjs/providers/hf-inference.js +27 -30
- package/dist/commonjs/providers/hyperbolic.d.ts.map +1 -1
- package/dist/commonjs/providers/hyperbolic.js +3 -3
- package/dist/commonjs/providers/nebius.d.ts.map +1 -1
- package/dist/commonjs/providers/nebius.js +2 -2
- package/dist/commonjs/providers/novita.d.ts +5 -6
- package/dist/commonjs/providers/novita.d.ts.map +1 -1
- package/dist/commonjs/providers/novita.js +66 -16
- package/dist/commonjs/providers/nscale.d.ts.map +1 -1
- package/dist/commonjs/providers/nscale.js +2 -2
- package/dist/commonjs/providers/ovhcloud.d.ts.map +1 -1
- package/dist/commonjs/providers/ovhcloud.js +2 -2
- package/dist/commonjs/providers/providerHelper.js +3 -3
- package/dist/commonjs/providers/replicate.js +4 -4
- package/dist/commonjs/providers/sambanova.d.ts +16 -0
- package/dist/commonjs/providers/sambanova.d.ts.map +1 -1
- package/dist/commonjs/providers/sambanova.js +2 -18
- package/dist/commonjs/providers/together.d.ts.map +1 -1
- package/dist/commonjs/providers/together.js +3 -3
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.js +2 -2
- package/dist/commonjs/utils/request.d.ts.map +1 -1
- package/dist/commonjs/utils/request.js +77 -12
- package/dist/commonjs/vendor/type-fest/basic.d.ts +33 -0
- package/dist/commonjs/vendor/type-fest/basic.d.ts.map +1 -0
- package/dist/commonjs/vendor/type-fest/basic.js +2 -0
- package/dist/esm/errors.d.ts +46 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +62 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/esm/lib/getInferenceProviderMapping.js +27 -16
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +5 -3
- package/dist/esm/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/esm/lib/makeRequestOptions.js +12 -11
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.d.ts.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/esm/providers/black-forest-labs.js +4 -4
- package/dist/esm/providers/fal-ai.d.ts.map +1 -1
- package/dist/esm/providers/fal-ai.js +29 -17
- package/dist/esm/providers/featherless-ai.d.ts.map +1 -1
- package/dist/esm/providers/featherless-ai.js +10 -4
- package/dist/esm/providers/hf-inference.d.ts.map +1 -1
- package/dist/esm/providers/hf-inference.js +27 -30
- package/dist/esm/providers/hyperbolic.d.ts.map +1 -1
- package/dist/esm/providers/hyperbolic.js +3 -3
- package/dist/esm/providers/nebius.d.ts.map +1 -1
- package/dist/esm/providers/nebius.js +2 -2
- package/dist/esm/providers/novita.d.ts +5 -6
- package/dist/esm/providers/novita.d.ts.map +1 -1
- package/dist/esm/providers/novita.js +66 -16
- package/dist/esm/providers/nscale.d.ts.map +1 -1
- package/dist/esm/providers/nscale.js +2 -2
- package/dist/esm/providers/ovhcloud.d.ts.map +1 -1
- package/dist/esm/providers/ovhcloud.js +2 -2
- package/dist/esm/providers/providerHelper.js +3 -3
- package/dist/esm/providers/replicate.js +4 -4
- package/dist/esm/providers/sambanova.d.ts +16 -0
- package/dist/esm/providers/sambanova.d.ts.map +1 -1
- package/dist/esm/providers/sambanova.js +2 -18
- package/dist/esm/providers/together.d.ts.map +1 -1
- package/dist/esm/providers/together.js +3 -3
- package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/esm/tasks/audio/automaticSpeechRecognition.js +2 -2
- package/dist/esm/utils/request.d.ts.map +1 -1
- package/dist/esm/utils/request.js +77 -12
- package/dist/esm/vendor/type-fest/basic.d.ts +33 -0
- package/dist/esm/vendor/type-fest/basic.d.ts.map +1 -0
- package/dist/esm/vendor/type-fest/basic.js +1 -0
- package/package.json +2 -2
- package/src/errors.ts +82 -0
- package/src/index.ts +1 -1
- package/src/lib/getInferenceProviderMapping.ts +42 -22
- package/src/lib/getProviderHelper.ts +9 -3
- package/src/lib/makeRequestOptions.ts +20 -11
- package/src/package.ts +1 -1
- package/src/providers/black-forest-labs.ts +14 -4
- package/src/providers/fal-ai.ts +59 -23
- package/src/providers/featherless-ai.ts +10 -4
- package/src/providers/hf-inference.ts +75 -34
- package/src/providers/hyperbolic.ts +3 -4
- package/src/providers/nebius.ts +2 -2
- package/src/providers/novita.ts +103 -23
- package/src/providers/nscale.ts +2 -2
- package/src/providers/ovhcloud.ts +2 -2
- package/src/providers/providerHelper.ts +3 -3
- package/src/providers/replicate.ts +4 -4
- package/src/providers/sambanova.ts +3 -4
- package/src/providers/together.ts +3 -3
- package/src/tasks/audio/automaticSpeechRecognition.ts +2 -2
- package/src/tasks/cv/textToVideo.ts +2 -2
- package/src/utils/request.ts +127 -14
- package/src/vendor/type-fest/basic.ts +31 -0
- package/src/vendor/type-fest/license-cc0 +121 -0
- package/src/vendor/type-fest/license-mit +9 -0
- package/dist/commonjs/lib/InferenceOutputError.d.ts +0 -4
- package/dist/commonjs/lib/InferenceOutputError.d.ts.map +0 -1
- package/dist/commonjs/lib/InferenceOutputError.js +0 -10
- package/dist/esm/lib/InferenceOutputError.d.ts +0 -4
- package/dist/esm/lib/InferenceOutputError.d.ts.map +0 -1
- package/dist/esm/lib/InferenceOutputError.js +0 -6
- package/src/lib/InferenceOutputError.ts +0 -8
|
@@ -17,10 +17,11 @@ exports.NovitaTextToVideoTask = exports.NovitaConversationalTask = exports.Novit
|
|
|
17
17
|
*
|
|
18
18
|
* Thanks!
|
|
19
19
|
*/
|
|
20
|
-
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
21
20
|
const isUrl_js_1 = require("../lib/isUrl.js");
|
|
21
|
+
const delay_js_1 = require("../utils/delay.js");
|
|
22
22
|
const omit_js_1 = require("../utils/omit.js");
|
|
23
23
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
24
|
+
const errors_js_1 = require("../errors.js");
|
|
24
25
|
const NOVITA_API_BASE_URL = "https://api.novita.ai";
|
|
25
26
|
class NovitaTextGenerationTask extends providerHelper_js_1.BaseTextGenerationTask {
|
|
26
27
|
constructor() {
|
|
@@ -45,29 +46,78 @@ class NovitaTextToVideoTask extends providerHelper_js_1.TaskProviderHelper {
|
|
|
45
46
|
super("novita", NOVITA_API_BASE_URL);
|
|
46
47
|
}
|
|
47
48
|
makeRoute(params) {
|
|
48
|
-
return `/v3/
|
|
49
|
+
return `/v3/async/${params.model}`;
|
|
49
50
|
}
|
|
50
51
|
preparePayload(params) {
|
|
52
|
+
const { num_inference_steps, ...restParameters } = params.args.parameters ?? {};
|
|
51
53
|
return {
|
|
52
54
|
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
53
|
-
...
|
|
55
|
+
...restParameters,
|
|
56
|
+
steps: num_inference_steps,
|
|
54
57
|
prompt: params.args.inputs,
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
|
-
async getResponse(response) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
async getResponse(response, url, headers) {
|
|
61
|
+
if (!url || !headers) {
|
|
62
|
+
throw new errors_js_1.InferenceClientInputError("URL and headers are required for text-to-video task");
|
|
63
|
+
}
|
|
64
|
+
const taskId = response.task_id;
|
|
65
|
+
if (!taskId) {
|
|
66
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Novita text-to-video API: no task ID found in the response");
|
|
67
|
+
}
|
|
68
|
+
const parsedUrl = new URL(url);
|
|
69
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/novita" : ""}`;
|
|
70
|
+
const resultUrl = `${baseUrl}/v3/async/task-result?task_id=${taskId}`;
|
|
71
|
+
let status = "";
|
|
72
|
+
let taskResult;
|
|
73
|
+
while (status !== "TASK_STATUS_SUCCEED" && status !== "TASK_STATUS_FAILED") {
|
|
74
|
+
await (0, delay_js_1.delay)(500);
|
|
75
|
+
const resultResponse = await fetch(resultUrl, { headers });
|
|
76
|
+
if (!resultResponse.ok) {
|
|
77
|
+
throw new errors_js_1.InferenceClientProviderApiError("Failed to fetch task result", { url: resultUrl, method: "GET", headers }, {
|
|
78
|
+
requestId: resultResponse.headers.get("x-request-id") ?? "",
|
|
79
|
+
status: resultResponse.status,
|
|
80
|
+
body: await resultResponse.text(),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
taskResult = await resultResponse.json();
|
|
85
|
+
if (taskResult &&
|
|
86
|
+
typeof taskResult === "object" &&
|
|
87
|
+
"task" in taskResult &&
|
|
88
|
+
taskResult.task &&
|
|
89
|
+
typeof taskResult.task === "object" &&
|
|
90
|
+
"status" in taskResult.task &&
|
|
91
|
+
typeof taskResult.task.status === "string") {
|
|
92
|
+
status = taskResult.task.status;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Novita text-to-video API: failed to get task status");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Novita text-to-video API: failed to parse task result");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (status === "TASK_STATUS_FAILED") {
|
|
103
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Novita text-to-video task failed");
|
|
104
|
+
}
|
|
105
|
+
if (typeof taskResult === "object" &&
|
|
106
|
+
!!taskResult &&
|
|
107
|
+
"videos" in taskResult &&
|
|
108
|
+
typeof taskResult.videos === "object" &&
|
|
109
|
+
!!taskResult.videos &&
|
|
110
|
+
Array.isArray(taskResult.videos) &&
|
|
111
|
+
taskResult.videos.length > 0 &&
|
|
112
|
+
"video_url" in taskResult.videos[0] &&
|
|
113
|
+
typeof taskResult.videos[0].video_url === "string" &&
|
|
114
|
+
(0, isUrl_js_1.isUrl)(taskResult.videos[0].video_url)) {
|
|
115
|
+
const urlResponse = await fetch(taskResult.videos[0].video_url);
|
|
116
|
+
return await urlResponse.blob();
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new errors_js_1.InferenceClientProviderOutputError(`Received malformed response from Novita text-to-video API: expected { videos: [{ video_url: string }] } format, got instead: ${JSON.stringify(taskResult)}`);
|
|
68
120
|
}
|
|
69
|
-
const urlResponse = await fetch(response.video.video_url);
|
|
70
|
-
return await urlResponse.blob();
|
|
71
121
|
}
|
|
72
122
|
}
|
|
73
123
|
exports.NovitaTextToVideoTask = NovitaTextToVideoTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nscale.d.ts","sourceRoot":"","sources":["../../../src/providers/nscale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"nscale.d.ts","sourceRoot":"","sources":["../../../src/providers/nscale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAK7G,UAAU,gCAAgC;IACzC,IAAI,EAAE,KAAK,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,sBAAsB;;CAInE;AAED,qBAAa,qBAAsB,SAAQ,kBAAmB,YAAW,qBAAqB;;IAK7F,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAU7E,SAAS,IAAI,MAAM;IAIb,WAAW,CAChB,QAAQ,EAAE,gCAAgC,EAC1C,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkBzB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NscaleTextToImageTask = exports.NscaleConversationalTask = void 0;
|
|
4
|
-
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
5
4
|
const omit_js_1 = require("../utils/omit.js");
|
|
6
5
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
7
|
const NSCALE_API_BASE_URL = "https://inference.api.nscale.com";
|
|
8
8
|
class NscaleConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
9
9
|
constructor() {
|
|
@@ -40,7 +40,7 @@ class NscaleTextToImageTask extends providerHelper_js_1.TaskProviderHelper {
|
|
|
40
40
|
}
|
|
41
41
|
return fetch(`data:image/jpeg;base64,${base64Data}`).then((res) => res.blob());
|
|
42
42
|
}
|
|
43
|
-
throw new
|
|
43
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Nscale text-to-image API");
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.NscaleTextToImageTask = NscaleTextToImageTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ovhcloud.d.ts","sourceRoot":"","sources":["../../../src/providers/ovhcloud.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"ovhcloud.d.ts","sourceRoot":"","sources":["../../../src/providers/ovhcloud.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACvH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAK9D,UAAU,4BAA6B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IACnF,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,gCAAgC,CAAC;QAChD,QAAQ,EAAE,OAAO,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACH;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;IAK5D,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAc1E,WAAW,CAAC,QAAQ,EAAE,4BAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAcjG"}
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.OvhCloudTextGenerationTask = exports.OvhCloudConversationalTask = void 0;
|
|
20
20
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
21
|
-
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
22
21
|
const omit_js_1 = require("../utils/omit.js");
|
|
22
|
+
const errors_js_1 = require("../errors.js");
|
|
23
23
|
const OVHCLOUD_API_BASE_URL = "https://oai.endpoints.kepler.ai.cloud.ovh.net";
|
|
24
24
|
class OvhCloudConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
25
25
|
constructor() {
|
|
@@ -54,7 +54,7 @@ class OvhCloudTextGenerationTask extends providerHelper_js_1.BaseTextGenerationT
|
|
|
54
54
|
generated_text: completion.text,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
throw new
|
|
57
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from OVHcloud text generation API");
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
exports.OvhCloudTextGenerationTask = OvhCloudTextGenerationTask;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseTextGenerationTask = exports.BaseConversationalTask = exports.TaskProviderHelper = void 0;
|
|
4
4
|
const config_js_1 = require("../config.js");
|
|
5
|
-
const
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const toArray_js_1 = require("../utils/toArray.js");
|
|
7
7
|
/**
|
|
8
8
|
* Base class for task-specific provider helpers
|
|
@@ -78,7 +78,7 @@ class BaseConversationalTask extends TaskProviderHelper {
|
|
|
78
78
|
typeof response?.usage === "object") {
|
|
79
79
|
return response;
|
|
80
80
|
}
|
|
81
|
-
throw new
|
|
81
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Expected ChatCompletionOutput");
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
exports.BaseConversationalTask = BaseConversationalTask;
|
|
@@ -102,7 +102,7 @@ class BaseTextGenerationTask extends TaskProviderHelper {
|
|
|
102
102
|
res.every((x) => typeof x === "object" && !!x && "generated_text" in x && typeof x.generated_text === "string")) {
|
|
103
103
|
return res[0];
|
|
104
104
|
}
|
|
105
|
-
throw new
|
|
105
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Expected Array<{generated_text: string}>");
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
exports.BaseTextGenerationTask = BaseTextGenerationTask;
|
|
@@ -17,7 +17,7 @@ exports.ReplicateTextToVideoTask = exports.ReplicateTextToSpeechTask = exports.R
|
|
|
17
17
|
*
|
|
18
18
|
* Thanks!
|
|
19
19
|
*/
|
|
20
|
-
const
|
|
20
|
+
const errors_js_1 = require("../errors.js");
|
|
21
21
|
const isUrl_js_1 = require("../lib/isUrl.js");
|
|
22
22
|
const omit_js_1 = require("../utils/omit.js");
|
|
23
23
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
@@ -84,7 +84,7 @@ class ReplicateTextToImageTask extends ReplicateTask {
|
|
|
84
84
|
const urlResponse = await fetch(res.output[0]);
|
|
85
85
|
return await urlResponse.blob();
|
|
86
86
|
}
|
|
87
|
-
throw new
|
|
87
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Replicate text-to-image API");
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
exports.ReplicateTextToImageTask = ReplicateTextToImageTask;
|
|
@@ -115,7 +115,7 @@ class ReplicateTextToSpeechTask extends ReplicateTask {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
throw new
|
|
118
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Replicate text-to-speech API");
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
exports.ReplicateTextToSpeechTask = ReplicateTextToSpeechTask;
|
|
@@ -129,7 +129,7 @@ class ReplicateTextToVideoTask extends ReplicateTask {
|
|
|
129
129
|
const urlResponse = await fetch(response.output);
|
|
130
130
|
return await urlResponse.blob();
|
|
131
131
|
}
|
|
132
|
-
throw new
|
|
132
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Replicate text-to-video API");
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
exports.ReplicateTextToVideoTask = ReplicateTextToVideoTask;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => Sambanova model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/sambanova/models
|
|
5
|
+
*
|
|
6
|
+
* This is a publicly available mapping.
|
|
7
|
+
*
|
|
8
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
9
|
+
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
10
|
+
*
|
|
11
|
+
* - If you work at Sambanova and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
12
|
+
* - If you're a community member and want to add a new supported HF model to Sambanova, please open an issue on the present repo
|
|
13
|
+
* and we will tag Sambanova team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
1
17
|
import type { FeatureExtractionOutput } from "@huggingface/tasks";
|
|
2
18
|
import type { BodyParams } from "../types.js";
|
|
3
19
|
import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,qBAAa,2BAA4B,SAAQ,sBAAsB;;CAItE;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKnG,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAStF,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpE"}
|
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SambanovaFeatureExtractionTask = exports.SambanovaConversationalTask = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* See the registered mapping of HF model ID => Sambanova model ID here:
|
|
6
|
-
*
|
|
7
|
-
* https://huggingface.co/api/partners/sambanova/models
|
|
8
|
-
*
|
|
9
|
-
* This is a publicly available mapping.
|
|
10
|
-
*
|
|
11
|
-
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
12
|
-
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
13
|
-
*
|
|
14
|
-
* - If you work at Sambanova and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
15
|
-
* - If you're a community member and want to add a new supported HF model to Sambanova, please open an issue on the present repo
|
|
16
|
-
* and we will tag Sambanova team members.
|
|
17
|
-
*
|
|
18
|
-
* Thanks!
|
|
19
|
-
*/
|
|
20
|
-
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
21
4
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
22
6
|
class SambanovaConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
23
7
|
constructor() {
|
|
24
8
|
super("sambanova", "https://api.sambanova.ai");
|
|
@@ -36,7 +20,7 @@ class SambanovaFeatureExtractionTask extends providerHelper_js_1.TaskProviderHel
|
|
|
36
20
|
if (typeof response === "object" && "data" in response && Array.isArray(response.data)) {
|
|
37
21
|
return response.data.map((item) => item.embedding);
|
|
38
22
|
}
|
|
39
|
-
throw new
|
|
23
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Sambanova feature-extraction (embeddings) API");
|
|
40
24
|
}
|
|
41
25
|
preparePayload(params) {
|
|
42
26
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../../src/providers/together.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../../src/providers/together.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACvH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAK7B,UAAU,4BAA6B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IACnF,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,gCAAgC,CAAC;QAChD,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,OAAO,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACH;AAED,UAAU,6BAA6B;IACtC,IAAI,EAAE,KAAK,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACH;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;IAK5D,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQrD,WAAW,CAAC,QAAQ,EAAE,4BAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAcjG;AAED,qBAAa,uBAAwB,SAAQ,kBAAmB,YAAW,qBAAqB;;IAK/F,SAAS,IAAI,MAAM;IAInB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUrD,WAAW,CAAC,QAAQ,EAAE,6BAA6B,EAAE,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkB/G"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TogetherTextToImageTask = exports.TogetherTextGenerationTask = exports.TogetherConversationalTask = void 0;
|
|
4
|
-
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
5
4
|
const omit_js_1 = require("../utils/omit.js");
|
|
6
5
|
const providerHelper_js_1 = require("./providerHelper.js");
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
7
|
const TOGETHER_API_BASE_URL = "https://api.together.xyz";
|
|
8
8
|
class TogetherConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
9
9
|
constructor() {
|
|
@@ -32,7 +32,7 @@ class TogetherTextGenerationTask extends providerHelper_js_1.BaseTextGenerationT
|
|
|
32
32
|
generated_text: completion.text,
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
throw new
|
|
35
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Together text generation API");
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.TogetherTextGenerationTask = TogetherTextGenerationTask;
|
|
@@ -65,7 +65,7 @@ class TogetherTextToImageTask extends providerHelper_js_1.TaskProviderHelper {
|
|
|
65
65
|
}
|
|
66
66
|
return fetch(`data:image/jpeg;base64,${base64Data}`).then((res) => res.blob());
|
|
67
67
|
}
|
|
68
|
-
throw new
|
|
68
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Together text-to-image API");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
exports.TogetherTextToImageTask = TogetherTextToImageTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticSpeechRecognition.d.ts","sourceRoot":"","sources":["../../../../src/tasks/audio/automaticSpeechRecognition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"automaticSpeechRecognition.d.ts","sourceRoot":"","sources":["../../../../src/tasks/audio/automaticSpeechRecognition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAG5G,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,8BAA8B,GAAG,QAAQ,GAAG,CAAC,+BAA+B,GAAG,gBAAgB,CAAC,CAAC;AAC7G;;;GAGG;AACH,wBAAsB,0BAA0B,CAC/C,IAAI,EAAE,8BAA8B,EACpC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,gCAAgC,CAAC,CAa3C"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.automaticSpeechRecognition = automaticSpeechRecognition;
|
|
4
4
|
const getInferenceProviderMapping_js_1 = require("../../lib/getInferenceProviderMapping.js");
|
|
5
5
|
const getProviderHelper_js_1 = require("../../lib/getProviderHelper.js");
|
|
6
|
-
const InferenceOutputError_js_1 = require("../../lib/InferenceOutputError.js");
|
|
7
6
|
const request_js_1 = require("../../utils/request.js");
|
|
7
|
+
const errors_js_1 = require("../../errors.js");
|
|
8
8
|
/**
|
|
9
9
|
* This task reads some audio input and outputs the said words within the audio files.
|
|
10
10
|
* Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
|
|
@@ -19,7 +19,7 @@ async function automaticSpeechRecognition(args, options) {
|
|
|
19
19
|
});
|
|
20
20
|
const isValidOutput = typeof res?.text === "string";
|
|
21
21
|
if (!isValidOutput) {
|
|
22
|
-
throw new
|
|
22
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from automatic-speech-recognition API");
|
|
23
23
|
}
|
|
24
24
|
return providerHelper.getResponse(res);
|
|
25
25
|
}
|
|
@@ -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;
|
|
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,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"}
|
|
@@ -4,6 +4,15 @@ exports.innerRequest = innerRequest;
|
|
|
4
4
|
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
|
+
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
|
+
}));
|
|
15
|
+
}
|
|
7
16
|
/**
|
|
8
17
|
* Primitive to make custom calls to the inference provider
|
|
9
18
|
*/
|
|
@@ -19,17 +28,37 @@ async function innerRequest(args, providerHelper, options) {
|
|
|
19
28
|
if (["application/json", "application/problem+json"].some((ct) => contentType?.startsWith(ct))) {
|
|
20
29
|
const output = await response.json();
|
|
21
30
|
if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
|
|
22
|
-
throw new
|
|
31
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Provider ${args.provider} does not seem to support chat completion for model ${args.model} . Error: ${JSON.stringify(output.error)}`, {
|
|
32
|
+
url,
|
|
33
|
+
method: info.method ?? "GET",
|
|
34
|
+
headers: info.headers,
|
|
35
|
+
body: requestArgsToJson(args),
|
|
36
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
23
37
|
}
|
|
24
|
-
if (output.error || output.detail) {
|
|
25
|
-
throw new
|
|
38
|
+
if (typeof output.error === "string" || typeof output.detail === "string") {
|
|
39
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${output.error ?? output.detail}`, {
|
|
40
|
+
url,
|
|
41
|
+
method: info.method ?? "GET",
|
|
42
|
+
headers: info.headers,
|
|
43
|
+
body: requestArgsToJson(args),
|
|
44
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
26
45
|
}
|
|
27
46
|
else {
|
|
28
|
-
throw new
|
|
47
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: an HTTP error occurred when requesting the provider.`, {
|
|
48
|
+
url,
|
|
49
|
+
method: info.method ?? "GET",
|
|
50
|
+
headers: info.headers,
|
|
51
|
+
body: requestArgsToJson(args),
|
|
52
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
29
53
|
}
|
|
30
54
|
}
|
|
31
55
|
const message = contentType?.startsWith("text/plain;") ? await response.text() : undefined;
|
|
32
|
-
throw new
|
|
56
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${message ?? "an HTTP error occurred when requesting the provider"}`, {
|
|
57
|
+
url,
|
|
58
|
+
method: info.method ?? "GET",
|
|
59
|
+
headers: info.headers,
|
|
60
|
+
body: requestArgsToJson(args),
|
|
61
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" });
|
|
33
62
|
}
|
|
34
63
|
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
|
|
35
64
|
const data = (await response.json());
|
|
@@ -51,24 +80,55 @@ async function* innerStreamingRequest(args, providerHelper, options) {
|
|
|
51
80
|
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
|
|
52
81
|
const output = await response.json();
|
|
53
82
|
if ([400, 422, 404, 500].includes(response.status) && options?.chatCompletion) {
|
|
54
|
-
throw new
|
|
83
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Provider ${args.provider} does not seem to support chat completion for model ${args.model} . Error: ${JSON.stringify(output.error)}`, {
|
|
84
|
+
url,
|
|
85
|
+
method: info.method ?? "GET",
|
|
86
|
+
headers: info.headers,
|
|
87
|
+
body: requestArgsToJson(args),
|
|
88
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
55
89
|
}
|
|
56
90
|
if (typeof output.error === "string") {
|
|
57
|
-
throw new
|
|
91
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${output.error}`, {
|
|
92
|
+
url,
|
|
93
|
+
method: info.method ?? "GET",
|
|
94
|
+
headers: info.headers,
|
|
95
|
+
body: requestArgsToJson(args),
|
|
96
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
58
97
|
}
|
|
59
98
|
if (output.error && "message" in output.error && typeof output.error.message === "string") {
|
|
60
99
|
/// OpenAI errors
|
|
61
|
-
throw new
|
|
100
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${output.error.message}`, {
|
|
101
|
+
url,
|
|
102
|
+
method: info.method ?? "GET",
|
|
103
|
+
headers: info.headers,
|
|
104
|
+
body: requestArgsToJson(args),
|
|
105
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
62
106
|
}
|
|
63
107
|
// Sambanova errors
|
|
64
108
|
if (typeof output.message === "string") {
|
|
65
|
-
throw new
|
|
109
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${output.message}`, {
|
|
110
|
+
url,
|
|
111
|
+
method: info.method ?? "GET",
|
|
112
|
+
headers: info.headers,
|
|
113
|
+
body: requestArgsToJson(args),
|
|
114
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output });
|
|
66
115
|
}
|
|
67
116
|
}
|
|
68
|
-
throw new
|
|
117
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: an HTTP error occurred when requesting the provider.`, {
|
|
118
|
+
url,
|
|
119
|
+
method: info.method ?? "GET",
|
|
120
|
+
headers: info.headers,
|
|
121
|
+
body: requestArgsToJson(args),
|
|
122
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
|
|
69
123
|
}
|
|
70
124
|
if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
|
|
71
|
-
throw new
|
|
125
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: server does not support event stream content type, it returned ` +
|
|
126
|
+
response.headers.get("content-type"), {
|
|
127
|
+
url,
|
|
128
|
+
method: info.method ?? "GET",
|
|
129
|
+
headers: info.headers,
|
|
130
|
+
body: requestArgsToJson(args),
|
|
131
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" });
|
|
72
132
|
}
|
|
73
133
|
if (!response.body) {
|
|
74
134
|
return;
|
|
@@ -102,7 +162,12 @@ async function* innerStreamingRequest(args, providerHelper, options) {
|
|
|
102
162
|
typeof data.error.message === "string"
|
|
103
163
|
? data.error.message
|
|
104
164
|
: JSON.stringify(data.error);
|
|
105
|
-
throw new
|
|
165
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: an occurred while streaming the response: ${errorStr}`, {
|
|
166
|
+
url,
|
|
167
|
+
method: info.method ?? "GET",
|
|
168
|
+
headers: info.headers,
|
|
169
|
+
body: requestArgsToJson(args),
|
|
170
|
+
}, { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data });
|
|
106
171
|
}
|
|
107
172
|
yield data;
|
|
108
173
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches a JSON object.
|
|
3
|
+
|
|
4
|
+
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
5
|
+
|
|
6
|
+
@category JSON
|
|
7
|
+
*/
|
|
8
|
+
export type JsonObject = {
|
|
9
|
+
[Key in string]: JsonValue;
|
|
10
|
+
} & {
|
|
11
|
+
[Key in string]?: JsonValue | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
Matches a JSON array.
|
|
15
|
+
|
|
16
|
+
@category JSON
|
|
17
|
+
*/
|
|
18
|
+
export type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
19
|
+
/**
|
|
20
|
+
Matches any valid JSON primitive value.
|
|
21
|
+
|
|
22
|
+
@category JSON
|
|
23
|
+
*/
|
|
24
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
25
|
+
/**
|
|
26
|
+
Matches any valid JSON value.
|
|
27
|
+
|
|
28
|
+
@see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
|
|
29
|
+
|
|
30
|
+
@category JSON
|
|
31
|
+
*/
|
|
32
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
33
|
+
//# sourceMappingURL=basic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../../../src/vendor/type-fest/basic.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AACF,MAAM,MAAM,UAAU,GAAG;KAAG,GAAG,IAAI,MAAM,GAAG,SAAS;CAAE,GAAG;KAAG,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS;CAAE,CAAC;AAEtG;;;;EAIE;AACF,MAAM,MAAM,SAAS,GAAG,SAAS,EAAE,GAAG,SAAS,SAAS,EAAE,CAAC;AAE3D;;;;EAIE;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D;;;;;;EAME;AACF,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { JsonObject } from "./vendor/type-fest/basic.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all inference-related errors.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class InferenceClientError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class InferenceClientInputError extends InferenceClientError {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
interface HttpRequest {
|
|
12
|
+
url: string;
|
|
13
|
+
method: string;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
body?: JsonObject;
|
|
16
|
+
}
|
|
17
|
+
interface HttpResponse {
|
|
18
|
+
requestId: string;
|
|
19
|
+
status: number;
|
|
20
|
+
body: JsonObject | string;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class InferenceClientHttpRequestError extends InferenceClientError {
|
|
23
|
+
httpRequest: HttpRequest;
|
|
24
|
+
httpResponse: HttpResponse;
|
|
25
|
+
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when the HTTP request to the provider fails, e.g. due to API issues or server errors.
|
|
29
|
+
*/
|
|
30
|
+
export declare class InferenceClientProviderApiError extends InferenceClientHttpRequestError {
|
|
31
|
+
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Thrown when the HTTP request to the hub fails, e.g. due to API issues or server errors.
|
|
35
|
+
*/
|
|
36
|
+
export declare class InferenceClientHubApiError extends InferenceClientHttpRequestError {
|
|
37
|
+
constructor(message: string, httpRequest: HttpRequest, httpResponse: HttpResponse);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when the inference output returned by the provider is invalid / does not match the expectations
|
|
41
|
+
*/
|
|
42
|
+
export declare class InferenceClientProviderOutputError extends InferenceClientError {
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;GAEG;AACH,8BAAsB,oBAAqB,SAAQ,KAAK;gBAC3C,OAAO,EAAE,MAAM;CAI3B;AAED,qBAAa,yBAA0B,SAAQ,oBAAoB;gBACtD,OAAO,EAAE,MAAM;CAI3B;AAED,UAAU,WAAW;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,UAAU,CAAC;CAClB;AAED,UAAU,YAAY;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;CAC1B;AAED,uBAAe,+BAAgC,SAAQ,oBAAoB;IAC1E,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;gBACf,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY;CAgBjF;AAED;;GAEG;AACH,qBAAa,+BAAgC,SAAQ,+BAA+B;gBACvE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY;CAIjF;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,+BAA+B;gBAClE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY;CAIjF;AAED;;GAEG;AACH,qBAAa,kCAAmC,SAAQ,oBAAoB;gBAC/D,OAAO,EAAE,MAAM;CAI3B"}
|