@huggingface/inference 3.15.0 → 4.0.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/README.md +102 -0
- 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 +4 -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 +2 -2
- 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.map +1 -1
- package/dist/commonjs/providers/novita.js +12 -8
- 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/snippets/getInferenceSnippets.d.ts +2 -1
- package/dist/commonjs/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +44 -5
- 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 +4 -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 +2 -2
- 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.map +1 -1
- package/dist/esm/providers/novita.js +12 -8
- 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/snippets/getInferenceSnippets.d.ts +2 -1
- package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/esm/snippets/getInferenceSnippets.js +44 -5
- 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 +8 -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 +2 -2
- 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 +30 -8
- 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/snippets/getInferenceSnippets.ts +69 -7
- package/src/tasks/audio/automaticSpeechRecognition.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
|
@@ -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;
|
|
@@ -4,6 +4,7 @@ import type { InferenceProviderOrPolicy } from "../types.js";
|
|
|
4
4
|
export type InferenceSnippetOptions = {
|
|
5
5
|
streaming?: boolean;
|
|
6
6
|
billTo?: string;
|
|
7
|
+
accessToken?: string;
|
|
7
8
|
} & Record<string, unknown>;
|
|
8
|
-
export declare function getInferenceSnippets(model: ModelDataMinimal,
|
|
9
|
+
export declare function getInferenceSnippets(model: ModelDataMinimal, provider: InferenceProviderOrPolicy, inferenceProviderMapping?: InferenceProviderModelMapping, opts?: Record<string, unknown>): InferenceSnippet[];
|
|
9
10
|
//# sourceMappingURL=getInferenceSnippets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInferenceSnippets.d.ts","sourceRoot":"","sources":["../../../src/snippets/getInferenceSnippets.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAG3F,OAAO,KAAK,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAGzF,MAAM,MAAM,uBAAuB,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"getInferenceSnippets.d.ts","sourceRoot":"","sources":["../../../src/snippets/getInferenceSnippets.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAG3F,OAAO,KAAK,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAGzF,MAAM,MAAM,uBAAuB,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAC5G,MAAM,EACN,OAAO,CACP,CAAC;AA0UF,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,yBAAyB,EACnC,wBAAwB,CAAC,EAAE,6BAA6B,EACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CAIpB"}
|
|
@@ -76,9 +76,10 @@ const HF_JS_METHODS = {
|
|
|
76
76
|
"text-to-speech": "textToSpeech",
|
|
77
77
|
translation: "translation",
|
|
78
78
|
};
|
|
79
|
+
const ACCESS_TOKEN_PLACEHOLDER = "<ACCESS_TOKEN>"; // Placeholder to replace with env variable in snippets
|
|
79
80
|
// Snippet generators
|
|
80
81
|
const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
81
|
-
return (model,
|
|
82
|
+
return (model, provider, inferenceProviderMapping, opts) => {
|
|
82
83
|
const providerModelId = inferenceProviderMapping?.providerId ?? model.id;
|
|
83
84
|
/// Hacky: hard-code conversational templates here
|
|
84
85
|
let task = model.pipeline_tag;
|
|
@@ -97,10 +98,11 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
|
97
98
|
console.error(`Failed to get provider helper for ${provider} (${task})`, e);
|
|
98
99
|
return [];
|
|
99
100
|
}
|
|
101
|
+
const accessTokenOrPlaceholder = opts?.accessToken ?? ACCESS_TOKEN_PLACEHOLDER;
|
|
100
102
|
/// Prepare inputs + make request
|
|
101
103
|
const inputs = inputPreparationFn ? inputPreparationFn(model, opts) : { inputs: (0, tasks_1.getModelInputSnippet)(model) };
|
|
102
104
|
const request = (0, makeRequestOptions_js_1.makeRequestOptionsFromResolvedModel)(providerModelId, providerHelper, {
|
|
103
|
-
accessToken,
|
|
105
|
+
accessToken: accessTokenOrPlaceholder,
|
|
104
106
|
provider,
|
|
105
107
|
...inputs,
|
|
106
108
|
}, inferenceProviderMapping, {
|
|
@@ -121,7 +123,7 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
|
121
123
|
}
|
|
122
124
|
/// Prepare template injection data
|
|
123
125
|
const params = {
|
|
124
|
-
accessToken,
|
|
126
|
+
accessToken: accessTokenOrPlaceholder,
|
|
125
127
|
authorizationHeader: request.info.headers?.Authorization,
|
|
126
128
|
baseUrl: removeSuffix(request.url, "/chat/completions"),
|
|
127
129
|
fullUrl: request.url,
|
|
@@ -185,6 +187,10 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
|
185
187
|
});
|
|
186
188
|
snippet = `${importSection}\n\n${snippet}`;
|
|
187
189
|
}
|
|
190
|
+
/// Replace access token placeholder
|
|
191
|
+
if (snippet.includes(ACCESS_TOKEN_PLACEHOLDER)) {
|
|
192
|
+
snippet = replaceAccessTokenPlaceholder(snippet, language, provider);
|
|
193
|
+
}
|
|
188
194
|
/// Snippet is ready!
|
|
189
195
|
return { language, client: client, content: snippet };
|
|
190
196
|
})
|
|
@@ -247,9 +253,9 @@ const snippets = {
|
|
|
247
253
|
"zero-shot-classification": snippetGenerator("zeroShotClassification"),
|
|
248
254
|
"zero-shot-image-classification": snippetGenerator("zeroShotImageClassification"),
|
|
249
255
|
};
|
|
250
|
-
function getInferenceSnippets(model,
|
|
256
|
+
function getInferenceSnippets(model, provider, inferenceProviderMapping, opts) {
|
|
251
257
|
return model.pipeline_tag && model.pipeline_tag in snippets
|
|
252
|
-
? snippets[model.pipeline_tag]?.(model,
|
|
258
|
+
? snippets[model.pipeline_tag]?.(model, provider, inferenceProviderMapping, opts) ?? []
|
|
253
259
|
: [];
|
|
254
260
|
}
|
|
255
261
|
// String manipulation helpers
|
|
@@ -310,3 +316,36 @@ function indentString(str) {
|
|
|
310
316
|
function removeSuffix(str, suffix) {
|
|
311
317
|
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
312
318
|
}
|
|
319
|
+
function replaceAccessTokenPlaceholder(snippet, language, provider) {
|
|
320
|
+
// If "opts.accessToken" is not set, the snippets are generated with a placeholder.
|
|
321
|
+
// Once snippets are rendered, we replace the placeholder with code to fetch the access token from an environment variable.
|
|
322
|
+
// Determine if HF_TOKEN or specific provider token should be used
|
|
323
|
+
const accessTokenEnvVar = !snippet.includes("https://") || // no URL provided => using a client => use $HF_TOKEN
|
|
324
|
+
snippet.includes("https://router.huggingface.co") || // explicit routed request => use $HF_TOKEN
|
|
325
|
+
provider == "hf-inference" // hf-inference provider => use $HF_TOKEN
|
|
326
|
+
? "HF_TOKEN"
|
|
327
|
+
: provider.toUpperCase().replace("-", "_") + "_API_KEY"; // e.g. "REPLICATE_API_KEY"
|
|
328
|
+
// Replace the placeholder with the env variable
|
|
329
|
+
if (language === "sh") {
|
|
330
|
+
snippet = snippet.replace(`'Authorization: Bearer ${ACCESS_TOKEN_PLACEHOLDER}'`, `"Authorization: Bearer $${accessTokenEnvVar}"` // e.g. "Authorization: Bearer $HF_TOKEN"
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
else if (language === "python") {
|
|
334
|
+
snippet = "import os\n" + snippet;
|
|
335
|
+
snippet = snippet.replace(`"${ACCESS_TOKEN_PLACEHOLDER}"`, `os.environ["${accessTokenEnvVar}"]` // e.g. os.environ["HF_TOKEN")
|
|
336
|
+
);
|
|
337
|
+
snippet = snippet.replace(`"Bearer ${ACCESS_TOKEN_PLACEHOLDER}"`, `f"Bearer {os.environ['${accessTokenEnvVar}']}"` // e.g. f"Bearer {os.environ['HF_TOKEN']}"
|
|
338
|
+
);
|
|
339
|
+
snippet = snippet.replace(`"Key ${ACCESS_TOKEN_PLACEHOLDER}"`, `f"Key {os.environ['${accessTokenEnvVar}']}"` // e.g. f"Key {os.environ['FAL_AI_API_KEY']}"
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
else if (language === "js") {
|
|
343
|
+
snippet = snippet.replace(`"${ACCESS_TOKEN_PLACEHOLDER}"`, `process.env.${accessTokenEnvVar}` // e.g. process.env.HF_TOKEN
|
|
344
|
+
);
|
|
345
|
+
snippet = snippet.replace(`Authorization: "Bearer ${ACCESS_TOKEN_PLACEHOLDER}",`, `Authorization: \`Bearer $\{process.env.${accessTokenEnvVar}}\`,` // e.g. Authorization: `Bearer ${process.env.HF_TOKEN}`,
|
|
346
|
+
);
|
|
347
|
+
snippet = snippet.replace(`Authorization: "Key ${ACCESS_TOKEN_PLACEHOLDER}",`, `Authorization: \`Key $\{process.env.${accessTokenEnvVar}}\`,` // e.g. Authorization: `Key ${process.env.FAL_AI_API_KEY}`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return snippet;
|
|
351
|
+
}
|
|
@@ -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" || typeof output.message === "string") {
|
|
39
|
+
throw new errors_js_1.InferenceClientProviderApiError(`Failed to perform inference: ${output.error ?? output.detail ?? output.message}`, {
|
|
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"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all inference-related errors.
|
|
3
|
+
*/
|
|
4
|
+
export class InferenceClientError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "InferenceClientError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class InferenceClientInputError extends InferenceClientError {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "InputError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class InferenceClientHttpRequestError extends InferenceClientError {
|
|
17
|
+
httpRequest;
|
|
18
|
+
httpResponse;
|
|
19
|
+
constructor(message, httpRequest, httpResponse) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.httpRequest = {
|
|
22
|
+
...httpRequest,
|
|
23
|
+
...(httpRequest.headers
|
|
24
|
+
? {
|
|
25
|
+
headers: {
|
|
26
|
+
...httpRequest.headers,
|
|
27
|
+
...("Authorization" in httpRequest.headers ? { Authorization: `Bearer [redacted]` } : undefined),
|
|
28
|
+
/// redact authentication in the request headers
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
: undefined),
|
|
32
|
+
};
|
|
33
|
+
this.httpResponse = httpResponse;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Thrown when the HTTP request to the provider fails, e.g. due to API issues or server errors.
|
|
38
|
+
*/
|
|
39
|
+
export class InferenceClientProviderApiError extends InferenceClientHttpRequestError {
|
|
40
|
+
constructor(message, httpRequest, httpResponse) {
|
|
41
|
+
super(message, httpRequest, httpResponse);
|
|
42
|
+
this.name = "ProviderApiError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when the HTTP request to the hub fails, e.g. due to API issues or server errors.
|
|
47
|
+
*/
|
|
48
|
+
export class InferenceClientHubApiError extends InferenceClientHttpRequestError {
|
|
49
|
+
constructor(message, httpRequest, httpResponse) {
|
|
50
|
+
super(message, httpRequest, httpResponse);
|
|
51
|
+
this.name = "HubApiError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Thrown when the inference output returned by the provider is invalid / does not match the expectations
|
|
56
|
+
*/
|
|
57
|
+
export class InferenceClientProviderOutputError extends InferenceClientError {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "ProviderOutputError";
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient.js";
|
|
2
|
-
export
|
|
2
|
+
export * from "./errors.js";
|
|
3
3
|
export * from "./types.js";
|
|
4
4
|
export * from "./tasks/index.js";
|
|
5
5
|
import * as snippets from "./snippets/index.js";
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|