@huggingface/inference 4.7.1 → 4.9.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 +3 -0
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +9 -0
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/consts.d.ts.map +1 -1
- package/dist/commonjs/providers/consts.js +2 -0
- package/dist/commonjs/providers/publicai.d.ts +5 -0
- package/dist/commonjs/providers/publicai.d.ts.map +1 -0
- package/dist/commonjs/providers/publicai.js +10 -0
- package/dist/commonjs/providers/replicate.d.ts +8 -1
- package/dist/commonjs/providers/replicate.d.ts.map +1 -1
- package/dist/commonjs/providers/replicate.js +46 -1
- package/dist/commonjs/providers/zai-org.d.ts +24 -0
- package/dist/commonjs/providers/zai-org.d.ts.map +1 -0
- package/dist/commonjs/providers/zai-org.js +36 -0
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.js +0 -5
- package/dist/commonjs/types.d.ts +2 -2
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +2 -0
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +9 -0
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/consts.d.ts.map +1 -1
- package/dist/esm/providers/consts.js +2 -0
- package/dist/esm/providers/publicai.d.ts +5 -0
- package/dist/esm/providers/publicai.d.ts.map +1 -0
- package/dist/esm/providers/publicai.js +6 -0
- package/dist/esm/providers/replicate.d.ts +8 -1
- package/dist/esm/providers/replicate.d.ts.map +1 -1
- package/dist/esm/providers/replicate.js +44 -0
- package/dist/esm/providers/zai-org.d.ts +24 -0
- package/dist/esm/providers/zai-org.d.ts.map +1 -0
- package/dist/esm/providers/zai-org.js +32 -0
- package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/esm/tasks/audio/automaticSpeechRecognition.js +0 -5
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +2 -0
- package/package.json +2 -2
- package/src/lib/getProviderHelper.ts +9 -0
- package/src/package.ts +1 -1
- package/src/providers/consts.ts +2 -0
- package/src/providers/publicai.ts +7 -0
- package/src/providers/replicate.ts +61 -0
- package/src/providers/zai-org.ts +37 -0
- package/src/tasks/audio/automaticSpeechRecognition.ts +0 -5
- package/src/types.ts +2 -0
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ Currently, we support the following providers:
|
|
|
56
56
|
- [Novita](https://novita.ai)
|
|
57
57
|
- [Nscale](https://nscale.com)
|
|
58
58
|
- [OVHcloud](https://endpoints.ai.cloud.ovh.net/)
|
|
59
|
+
- [Public AI](https://publicai.co)
|
|
59
60
|
- [Replicate](https://replicate.com)
|
|
60
61
|
- [Sambanova](https://sambanova.ai)
|
|
61
62
|
- [Scaleway](https://www.scaleway.com/en/generative-apis/)
|
|
@@ -64,6 +65,7 @@ Currently, we support the following providers:
|
|
|
64
65
|
- [Cohere](https://cohere.com)
|
|
65
66
|
- [Cerebras](https://cerebras.ai/)
|
|
66
67
|
- [Groq](https://groq.com)
|
|
68
|
+
- [Z.ai](https://z.ai/)
|
|
67
69
|
|
|
68
70
|
To send requests to a third-party provider, you have to pass the `provider` parameter to the inference function. The default value of the `provider` parameter is "auto", which will select the first of the providers available for the model, sorted by your preferred order in https://hf.co/settings/inference-providers.
|
|
69
71
|
|
|
@@ -99,6 +101,7 @@ Only a subset of models are supported when requesting third-party providers. You
|
|
|
99
101
|
- [Cerebras supported models](https://huggingface.co/api/partners/cerebras/models)
|
|
100
102
|
- [Groq supported models](https://console.groq.com/docs/models)
|
|
101
103
|
- [Novita AI supported models](https://huggingface.co/api/partners/novita/models)
|
|
104
|
+
- [Z.ai supported models](https://huggingface.co/api/partners/zai-org/models)
|
|
102
105
|
|
|
103
106
|
❗**Important note:** To be compatible, the third-party API must adhere to the "standard" shape API we expect on HF model pages for each pipeline task type.
|
|
104
107
|
This is not an issue for LLMs as everyone converged on the OpenAI API anyways, but can be more tricky for other tasks like "text-to-image" or "automatic-speech-recognition" where there exists no standard API. Let us know if any help is needed or if we can make things easier for you!
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACX,6BAA6B,EAC7B,sBAAsB,EACtB,oCAAoC,EACpC,wBAAwB,EACxB,mCAAmC,EACnC,2BAA2B,EAC3B,kBAAkB,EAClB,6BAA6B,EAC7B,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,2BAA2B,EAC3B,4BAA4B,EAC5B,uBAAuB,EACvB,gCAAgC,EAChC,+BAA+B,EAC/B,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,6BAA6B,EAC7B,qBAAqB,EACrB,iCAAiC,EACjC,gCAAgC,EAChC,qCAAqC,EACrC,MAAM,gCAAgC,CAAC;AAMxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG/F,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAkHnG,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB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yB,EACnC,IAAI,EAAE,qBAAqB,GACzB,4BAA4B,GAAG,kBAAkB,CAAC;AACrD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,0BAA0B,GAC9B,gCAAgC,GAAG,kBAAkB,CAAC;AACzD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,wBAAwB,GAC5B,+BAA+B,GAAG,kBAAkB,CAAC;AACxD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,oBAAoB,GACxB,2BAA2B,GAAG,kBAAkB,CAAC;AACpD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,sBAAsB,GAC1B,6BAA6B,GAAG,kBAAkB,CAAC;AACtD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GACjB,qBAAqB,GAAG,kBAAkB,CAAC;AAC9C,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,eAAe,GACnB,uBAAuB,GAAG,kBAAkB,CAAC;AAChD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,2BAA2B,GAC/B,iCAAiC,GAAG,kBAAkB,CAAC;AAC1D,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GAAG,SAAS,GAC7B,kBAAkB,CAAC"}
|
|
@@ -49,10 +49,12 @@ const Novita = __importStar(require("../providers/novita.js"));
|
|
|
49
49
|
const Nscale = __importStar(require("../providers/nscale.js"));
|
|
50
50
|
const OpenAI = __importStar(require("../providers/openai.js"));
|
|
51
51
|
const OvhCloud = __importStar(require("../providers/ovhcloud.js"));
|
|
52
|
+
const PublicAI = __importStar(require("../providers/publicai.js"));
|
|
52
53
|
const Replicate = __importStar(require("../providers/replicate.js"));
|
|
53
54
|
const Sambanova = __importStar(require("../providers/sambanova.js"));
|
|
54
55
|
const Scaleway = __importStar(require("../providers/scaleway.js"));
|
|
55
56
|
const Together = __importStar(require("../providers/together.js"));
|
|
57
|
+
const Zai = __importStar(require("../providers/zai-org.js"));
|
|
56
58
|
const errors_js_1 = require("../errors.js");
|
|
57
59
|
exports.PROVIDERS = {
|
|
58
60
|
"black-forest-labs": {
|
|
@@ -141,11 +143,15 @@ exports.PROVIDERS = {
|
|
|
141
143
|
conversational: new OvhCloud.OvhCloudConversationalTask(),
|
|
142
144
|
"text-generation": new OvhCloud.OvhCloudTextGenerationTask(),
|
|
143
145
|
},
|
|
146
|
+
publicai: {
|
|
147
|
+
conversational: new PublicAI.PublicAIConversationalTask(),
|
|
148
|
+
},
|
|
144
149
|
replicate: {
|
|
145
150
|
"text-to-image": new Replicate.ReplicateTextToImageTask(),
|
|
146
151
|
"text-to-speech": new Replicate.ReplicateTextToSpeechTask(),
|
|
147
152
|
"text-to-video": new Replicate.ReplicateTextToVideoTask(),
|
|
148
153
|
"image-to-image": new Replicate.ReplicateImageToImageTask(),
|
|
154
|
+
"automatic-speech-recognition": new Replicate.ReplicateAutomaticSpeechRecognitionTask(),
|
|
149
155
|
},
|
|
150
156
|
sambanova: {
|
|
151
157
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
@@ -161,6 +167,9 @@ exports.PROVIDERS = {
|
|
|
161
167
|
conversational: new Together.TogetherConversationalTask(),
|
|
162
168
|
"text-generation": new Together.TogetherTextGenerationTask(),
|
|
163
169
|
},
|
|
170
|
+
"zai-org": {
|
|
171
|
+
conversational: new Zai.ZaiConversationalTask(),
|
|
172
|
+
},
|
|
164
173
|
};
|
|
165
174
|
function getProviderHelper(provider, task) {
|
|
166
175
|
if ((provider === "hf-inference" && !task) || provider === "auto") {
|
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.
|
|
5
|
+
exports.PACKAGE_VERSION = "4.9.0";
|
|
6
6
|
exports.PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACrD,iBAAiB,EACjB,MAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACrD,iBAAiB,EACjB,MAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,CA4B9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicai.d.ts","sourceRoot":"","sources":["../../../src/providers/publicai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublicAIConversationalTask = void 0;
|
|
4
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
5
|
+
class PublicAIConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("publicai", "https://api.publicai.co");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.PublicAIConversationalTask = PublicAIConversationalTask;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BodyParams, HeaderParams, RequestArgs, UrlParams } from "../types.js";
|
|
2
|
-
import { TaskProviderHelper, type ImageToImageTaskHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper.js";
|
|
2
|
+
import { TaskProviderHelper, type AutomaticSpeechRecognitionTaskHelper, type ImageToImageTaskHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper.js";
|
|
3
3
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
4
|
+
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition.js";
|
|
5
|
+
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
4
6
|
export interface ReplicateOutput {
|
|
5
7
|
output?: string | string[];
|
|
6
8
|
}
|
|
@@ -22,6 +24,11 @@ export declare class ReplicateTextToSpeechTask extends ReplicateTask {
|
|
|
22
24
|
export declare class ReplicateTextToVideoTask extends ReplicateTask implements TextToVideoTaskHelper {
|
|
23
25
|
getResponse(response: ReplicateOutput): Promise<Blob>;
|
|
24
26
|
}
|
|
27
|
+
export declare class ReplicateAutomaticSpeechRecognitionTask extends ReplicateTask implements AutomaticSpeechRecognitionTaskHelper {
|
|
28
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
29
|
+
preparePayloadAsync(args: AutomaticSpeechRecognitionArgs): Promise<RequestArgs>;
|
|
30
|
+
getResponse(response: ReplicateOutput): Promise<AutomaticSpeechRecognitionOutput>;
|
|
31
|
+
}
|
|
25
32
|
export declare class ReplicateImageToImageTask extends ReplicateTask implements ImageToImageTaskHelper {
|
|
26
33
|
preparePayload(params: BodyParams<ImageToImageArgs>): Record<string, unknown>;
|
|
27
34
|
preparePayloadAsync(args: ImageToImageArgs): Promise<RequestArgs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicate.d.ts","sourceRoot":"","sources":["../../../src/providers/replicate.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EACN,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"replicate.d.ts","sourceRoot":"","sources":["../../../src/providers/replicate.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EACN,kBAAkB,EAClB,KAAK,oCAAoC,EACzC,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,8CAA8C,CAAC;AACnG,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAE3E,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3B;AAED,uBAAe,aAAc,SAAQ,kBAAkB;gBAC1C,GAAG,CAAC,EAAE,MAAM;IAIxB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAMpC,c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G;AAED,qBAAa,yBAA0B,SAAQ,aAAc,YAAW,sBAAsB;IACpF,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAehF,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;IAcxD,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CA0BpE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReplicateImageToImageTask = exports.ReplicateTextToVideoTask = exports.ReplicateTextToSpeechTask = exports.ReplicateTextToImageTask = void 0;
|
|
3
|
+
exports.ReplicateImageToImageTask = exports.ReplicateAutomaticSpeechRecognitionTask = exports.ReplicateTextToVideoTask = exports.ReplicateTextToSpeechTask = exports.ReplicateTextToImageTask = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* See the registered mapping of HF model ID => Replicate model ID here:
|
|
6
6
|
*
|
|
@@ -137,6 +137,51 @@ class ReplicateTextToVideoTask extends ReplicateTask {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
exports.ReplicateTextToVideoTask = ReplicateTextToVideoTask;
|
|
140
|
+
class ReplicateAutomaticSpeechRecognitionTask extends ReplicateTask {
|
|
141
|
+
preparePayload(params) {
|
|
142
|
+
return {
|
|
143
|
+
input: {
|
|
144
|
+
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
145
|
+
...params.args.parameters,
|
|
146
|
+
audio: params.args.inputs, // This will be processed in preparePayloadAsync
|
|
147
|
+
},
|
|
148
|
+
version: params.model.includes(":") ? params.model.split(":")[1] : undefined,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async preparePayloadAsync(args) {
|
|
152
|
+
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
153
|
+
if (!blob || !(blob instanceof Blob)) {
|
|
154
|
+
throw new Error("Audio input must be a Blob");
|
|
155
|
+
}
|
|
156
|
+
// Convert Blob to base64 data URL
|
|
157
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
158
|
+
const base64 = (0, base64FromBytes_js_1.base64FromBytes)(bytes);
|
|
159
|
+
const audioInput = `data:${blob.type || "audio/wav"};base64,${base64}`;
|
|
160
|
+
return {
|
|
161
|
+
...("data" in args ? (0, omit_js_1.omit)(args, "data") : (0, omit_js_1.omit)(args, "inputs")),
|
|
162
|
+
inputs: audioInput,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async getResponse(response) {
|
|
166
|
+
if (typeof response?.output === "string")
|
|
167
|
+
return { text: response.output };
|
|
168
|
+
if (Array.isArray(response?.output) && typeof response.output[0] === "string")
|
|
169
|
+
return { text: response.output[0] };
|
|
170
|
+
const out = response?.output;
|
|
171
|
+
if (out && typeof out === "object") {
|
|
172
|
+
if (typeof out.transcription === "string")
|
|
173
|
+
return { text: out.transcription };
|
|
174
|
+
if (typeof out.translation === "string")
|
|
175
|
+
return { text: out.translation };
|
|
176
|
+
if (typeof out.txt_file === "string") {
|
|
177
|
+
const r = await fetch(out.txt_file);
|
|
178
|
+
return { text: await r.text() };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Replicate automatic-speech-recognition API");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.ReplicateAutomaticSpeechRecognitionTask = ReplicateAutomaticSpeechRecognitionTask;
|
|
140
185
|
class ReplicateImageToImageTask extends ReplicateTask {
|
|
141
186
|
preparePayload(params) {
|
|
142
187
|
return {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => ZAI model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/zai-org/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 zai 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 zai, please open an issue on the present repo
|
|
13
|
+
* and we will tag zai team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper.js";
|
|
18
|
+
import type { HeaderParams } from "../types.js";
|
|
19
|
+
export declare class ZaiConversationalTask extends BaseConversationalTask {
|
|
20
|
+
constructor();
|
|
21
|
+
prepareHeaders(params: HeaderParams, binary: boolean): Record<string, string>;
|
|
22
|
+
makeRoute(): string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=zai-org.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zai-org.d.ts","sourceRoot":"","sources":["../../../src/providers/zai-org.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,qBAAa,qBAAsB,SAAQ,sBAAsB;;IAKvD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAO7E,SAAS,IAAI,MAAM;CAG5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZaiConversationalTask = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* See the registered mapping of HF model ID => ZAI model ID here:
|
|
6
|
+
*
|
|
7
|
+
* https://huggingface.co/api/partners/zai-org/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 zai 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 zai, please open an issue on the present repo
|
|
16
|
+
* and we will tag zai team members.
|
|
17
|
+
*
|
|
18
|
+
* Thanks!
|
|
19
|
+
*/
|
|
20
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
21
|
+
const ZAI_API_BASE_URL = "https://api.z.ai";
|
|
22
|
+
class ZaiConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
23
|
+
constructor() {
|
|
24
|
+
super("zai-org", ZAI_API_BASE_URL);
|
|
25
|
+
}
|
|
26
|
+
prepareHeaders(params, binary) {
|
|
27
|
+
const headers = super.prepareHeaders(params, binary);
|
|
28
|
+
headers["x-source-channel"] = "hugging_face";
|
|
29
|
+
headers["accept-language"] = "en-US,en";
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
makeRoute() {
|
|
33
|
+
return "/api/paas/v4/chat/completions";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ZaiConversationalTask = ZaiConversationalTask;
|
|
@@ -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;AAG5G,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,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;AAEnD,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,CAS3C"}
|
|
@@ -4,7 +4,6 @@ exports.automaticSpeechRecognition = automaticSpeechRecognition;
|
|
|
4
4
|
const getInferenceProviderMapping_js_1 = require("../../lib/getInferenceProviderMapping.js");
|
|
5
5
|
const getProviderHelper_js_1 = require("../../lib/getProviderHelper.js");
|
|
6
6
|
const request_js_1 = require("../../utils/request.js");
|
|
7
|
-
const errors_js_1 = require("../../errors.js");
|
|
8
7
|
/**
|
|
9
8
|
* This task reads some audio input and outputs the said words within the audio files.
|
|
10
9
|
* Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
|
|
@@ -17,9 +16,5 @@ async function automaticSpeechRecognition(args, options) {
|
|
|
17
16
|
...options,
|
|
18
17
|
task: "automatic-speech-recognition",
|
|
19
18
|
});
|
|
20
|
-
const isValidOutput = typeof res?.text === "string";
|
|
21
|
-
if (!isValidOutput) {
|
|
22
|
-
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from automatic-speech-recognition API");
|
|
23
|
-
}
|
|
24
19
|
return providerHelper.getResponse(res);
|
|
25
20
|
}
|
package/dist/commonjs/types.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export interface Options {
|
|
|
36
36
|
billTo?: string;
|
|
37
37
|
}
|
|
38
38
|
export type InferenceTask = Exclude<PipelineType, "other"> | "conversational";
|
|
39
|
-
export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "replicate", "sambanova", "scaleway", "together"];
|
|
40
|
-
export declare const PROVIDERS_OR_POLICIES: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "replicate", "sambanova", "scaleway", "together", "auto"];
|
|
39
|
+
export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "publicai", "replicate", "sambanova", "scaleway", "together", "zai-org"];
|
|
40
|
+
export declare const PROVIDERS_OR_POLICIES: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "publicai", "replicate", "sambanova", "scaleway", "together", "zai-org", "auto"];
|
|
41
41
|
export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
|
|
42
42
|
export type InferenceProviderOrPolicy = (typeof PROVIDERS_OR_POLICIES)[number];
|
|
43
43
|
export interface InferenceProviderMappingEntry {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExF;;GAEG;AACH,MAAM,MAAM,OAAO,GA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E,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;IACpD,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
|
package/dist/commonjs/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACX,6BAA6B,EAC7B,sBAAsB,EACtB,oCAAoC,EACpC,wBAAwB,EACxB,mCAAmC,EACnC,2BAA2B,EAC3B,kBAAkB,EAClB,6BAA6B,EAC7B,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,2BAA2B,EAC3B,4BAA4B,EAC5B,uBAAuB,EACvB,gCAAgC,EAChC,+BAA+B,EAC/B,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,6BAA6B,EAC7B,qBAAqB,EACrB,iCAAiC,EACjC,gCAAgC,EAChC,qCAAqC,EACrC,MAAM,gCAAgC,CAAC;AAMxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG/F,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAkHnG,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,eAAe,GACnB,qBAAqB,GAAG,kBAAkB,CAAC;AAC9C,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EAC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,EACnC,IAAI,EAAE,0BAA0B,GAC9B,gCAAgC,GAAG,kBAAkB,CAAC;AACzD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,wBAAwB,GAC5B,+BAA+B,GAAG,kBAAkB,CAAC;AACxD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,oBAAoB,GACxB,2BAA2B,GAAG,kBAAkB,CAAC;AACpD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,sBAAsB,GAC1B,6BAA6B,GAAG,kBAAkB,CAAC;AACtD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GACjB,qBAAqB,GAAG,kBAAkB,CAAC;AAC9C,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,eAAe,GACnB,uBAAuB,GAAG,kBAAkB,CAAC;AAChD,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,2BAA2B,GAC/B,iCAAiC,GAAG,kBAAkB,CAAC;AAC1D,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GAAG,SAAS,GAC7B,kBAAkB,CAAC"}
|
|
@@ -12,10 +12,12 @@ import * as Novita from "../providers/novita.js";
|
|
|
12
12
|
import * as Nscale from "../providers/nscale.js";
|
|
13
13
|
import * as OpenAI from "../providers/openai.js";
|
|
14
14
|
import * as OvhCloud from "../providers/ovhcloud.js";
|
|
15
|
+
import * as PublicAI from "../providers/publicai.js";
|
|
15
16
|
import * as Replicate from "../providers/replicate.js";
|
|
16
17
|
import * as Sambanova from "../providers/sambanova.js";
|
|
17
18
|
import * as Scaleway from "../providers/scaleway.js";
|
|
18
19
|
import * as Together from "../providers/together.js";
|
|
20
|
+
import * as Zai from "../providers/zai-org.js";
|
|
19
21
|
import { InferenceClientInputError } from "../errors.js";
|
|
20
22
|
export const PROVIDERS = {
|
|
21
23
|
"black-forest-labs": {
|
|
@@ -104,11 +106,15 @@ export const PROVIDERS = {
|
|
|
104
106
|
conversational: new OvhCloud.OvhCloudConversationalTask(),
|
|
105
107
|
"text-generation": new OvhCloud.OvhCloudTextGenerationTask(),
|
|
106
108
|
},
|
|
109
|
+
publicai: {
|
|
110
|
+
conversational: new PublicAI.PublicAIConversationalTask(),
|
|
111
|
+
},
|
|
107
112
|
replicate: {
|
|
108
113
|
"text-to-image": new Replicate.ReplicateTextToImageTask(),
|
|
109
114
|
"text-to-speech": new Replicate.ReplicateTextToSpeechTask(),
|
|
110
115
|
"text-to-video": new Replicate.ReplicateTextToVideoTask(),
|
|
111
116
|
"image-to-image": new Replicate.ReplicateImageToImageTask(),
|
|
117
|
+
"automatic-speech-recognition": new Replicate.ReplicateAutomaticSpeechRecognitionTask(),
|
|
112
118
|
},
|
|
113
119
|
sambanova: {
|
|
114
120
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
@@ -124,6 +130,9 @@ export const PROVIDERS = {
|
|
|
124
130
|
conversational: new Together.TogetherConversationalTask(),
|
|
125
131
|
"text-generation": new Together.TogetherTextGenerationTask(),
|
|
126
132
|
},
|
|
133
|
+
"zai-org": {
|
|
134
|
+
conversational: new Zai.ZaiConversationalTask(),
|
|
135
|
+
},
|
|
127
136
|
};
|
|
128
137
|
export function getProviderHelper(provider, task) {
|
|
129
138
|
if ((provider === "hf-inference" && !task) || provider === "auto") {
|
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.
|
|
2
|
+
export const PACKAGE_VERSION = "4.9.0";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACrD,iBAAiB,EACjB,MAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACrD,iBAAiB,EACjB,MAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,CA4B9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicai.d.ts","sourceRoot":"","sources":["../../../src/providers/publicai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BodyParams, HeaderParams, RequestArgs, UrlParams } from "../types.js";
|
|
2
|
-
import { TaskProviderHelper, type ImageToImageTaskHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper.js";
|
|
2
|
+
import { TaskProviderHelper, type AutomaticSpeechRecognitionTaskHelper, type ImageToImageTaskHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper.js";
|
|
3
3
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
4
|
+
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition.js";
|
|
5
|
+
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
4
6
|
export interface ReplicateOutput {
|
|
5
7
|
output?: string | string[];
|
|
6
8
|
}
|
|
@@ -22,6 +24,11 @@ export declare class ReplicateTextToSpeechTask extends ReplicateTask {
|
|
|
22
24
|
export declare class ReplicateTextToVideoTask extends ReplicateTask implements TextToVideoTaskHelper {
|
|
23
25
|
getResponse(response: ReplicateOutput): Promise<Blob>;
|
|
24
26
|
}
|
|
27
|
+
export declare class ReplicateAutomaticSpeechRecognitionTask extends ReplicateTask implements AutomaticSpeechRecognitionTaskHelper {
|
|
28
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
29
|
+
preparePayloadAsync(args: AutomaticSpeechRecognitionArgs): Promise<RequestArgs>;
|
|
30
|
+
getResponse(response: ReplicateOutput): Promise<AutomaticSpeechRecognitionOutput>;
|
|
31
|
+
}
|
|
25
32
|
export declare class ReplicateImageToImageTask extends ReplicateTask implements ImageToImageTaskHelper {
|
|
26
33
|
preparePayload(params: BodyParams<ImageToImageArgs>): Record<string, unknown>;
|
|
27
34
|
preparePayloadAsync(args: ImageToImageArgs): Promise<RequestArgs>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicate.d.ts","sourceRoot":"","sources":["../../../src/providers/replicate.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EACN,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"replicate.d.ts","sourceRoot":"","sources":["../../../src/providers/replicate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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAsBnD;AAED,qBAAa,yBAA0B,SAAQ,aAAa;IAClD,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAarD,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBpE;AAED,qBAAa,wBAAyB,SAAQ,aAAc,YAAW,qBAAqB;IAC5E,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAcpE;AAED,qBAAa,uCACZ,SAAQ,aACR,YAAW,oCAAoC;IAEtC,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAW9D,mBAAmB,CAAC,IAAI,EAAE,8BAA8B,GAAG,OAAO,CAAC,WAAW,CAAC;IAkBtE,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAuBhG;AAED,qBAAa,yBAA0B,SAAQ,aAAc,YAAW,sBAAsB;IACpF,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAehF,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;IAcxD,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CA0BpE"}
|
|
@@ -131,6 +131,50 @@ export class ReplicateTextToVideoTask extends ReplicateTask {
|
|
|
131
131
|
throw new InferenceClientProviderOutputError("Received malformed response from Replicate text-to-video API");
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
+
export class ReplicateAutomaticSpeechRecognitionTask extends ReplicateTask {
|
|
135
|
+
preparePayload(params) {
|
|
136
|
+
return {
|
|
137
|
+
input: {
|
|
138
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
139
|
+
...params.args.parameters,
|
|
140
|
+
audio: params.args.inputs, // This will be processed in preparePayloadAsync
|
|
141
|
+
},
|
|
142
|
+
version: params.model.includes(":") ? params.model.split(":")[1] : undefined,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async preparePayloadAsync(args) {
|
|
146
|
+
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
147
|
+
if (!blob || !(blob instanceof Blob)) {
|
|
148
|
+
throw new Error("Audio input must be a Blob");
|
|
149
|
+
}
|
|
150
|
+
// Convert Blob to base64 data URL
|
|
151
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
152
|
+
const base64 = base64FromBytes(bytes);
|
|
153
|
+
const audioInput = `data:${blob.type || "audio/wav"};base64,${base64}`;
|
|
154
|
+
return {
|
|
155
|
+
...("data" in args ? omit(args, "data") : omit(args, "inputs")),
|
|
156
|
+
inputs: audioInput,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async getResponse(response) {
|
|
160
|
+
if (typeof response?.output === "string")
|
|
161
|
+
return { text: response.output };
|
|
162
|
+
if (Array.isArray(response?.output) && typeof response.output[0] === "string")
|
|
163
|
+
return { text: response.output[0] };
|
|
164
|
+
const out = response?.output;
|
|
165
|
+
if (out && typeof out === "object") {
|
|
166
|
+
if (typeof out.transcription === "string")
|
|
167
|
+
return { text: out.transcription };
|
|
168
|
+
if (typeof out.translation === "string")
|
|
169
|
+
return { text: out.translation };
|
|
170
|
+
if (typeof out.txt_file === "string") {
|
|
171
|
+
const r = await fetch(out.txt_file);
|
|
172
|
+
return { text: await r.text() };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Replicate automatic-speech-recognition API");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
134
178
|
export class ReplicateImageToImageTask extends ReplicateTask {
|
|
135
179
|
preparePayload(params) {
|
|
136
180
|
return {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => ZAI model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/zai-org/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 zai 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 zai, please open an issue on the present repo
|
|
13
|
+
* and we will tag zai team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper.js";
|
|
18
|
+
import type { HeaderParams } from "../types.js";
|
|
19
|
+
export declare class ZaiConversationalTask extends BaseConversationalTask {
|
|
20
|
+
constructor();
|
|
21
|
+
prepareHeaders(params: HeaderParams, binary: boolean): Record<string, string>;
|
|
22
|
+
makeRoute(): string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=zai-org.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zai-org.d.ts","sourceRoot":"","sources":["../../../src/providers/zai-org.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,qBAAa,qBAAsB,SAAQ,sBAAsB;;IAKvD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAO7E,SAAS,IAAI,MAAM;CAG5B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => ZAI model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/zai-org/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 zai 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 zai, please open an issue on the present repo
|
|
13
|
+
* and we will tag zai team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper.js";
|
|
18
|
+
const ZAI_API_BASE_URL = "https://api.z.ai";
|
|
19
|
+
export class ZaiConversationalTask extends BaseConversationalTask {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("zai-org", ZAI_API_BASE_URL);
|
|
22
|
+
}
|
|
23
|
+
prepareHeaders(params, binary) {
|
|
24
|
+
const headers = super.prepareHeaders(params, binary);
|
|
25
|
+
headers["x-source-channel"] = "hugging_face";
|
|
26
|
+
headers["accept-language"] = "en-US,en";
|
|
27
|
+
return headers;
|
|
28
|
+
}
|
|
29
|
+
makeRoute() {
|
|
30
|
+
return "/api/paas/v4/chat/completions";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -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;AAG5G,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,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;AAEnD,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,CAS3C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
|
|
2
2
|
import { getProviderHelper } from "../../lib/getProviderHelper.js";
|
|
3
3
|
import { innerRequest } from "../../utils/request.js";
|
|
4
|
-
import { InferenceClientProviderOutputError } from "../../errors.js";
|
|
5
4
|
/**
|
|
6
5
|
* This task reads some audio input and outputs the said words within the audio files.
|
|
7
6
|
* Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
|
|
@@ -14,9 +13,5 @@ export async function automaticSpeechRecognition(args, options) {
|
|
|
14
13
|
...options,
|
|
15
14
|
task: "automatic-speech-recognition",
|
|
16
15
|
});
|
|
17
|
-
const isValidOutput = typeof res?.text === "string";
|
|
18
|
-
if (!isValidOutput) {
|
|
19
|
-
throw new InferenceClientProviderOutputError("Received malformed response from automatic-speech-recognition API");
|
|
20
|
-
}
|
|
21
16
|
return providerHelper.getResponse(res);
|
|
22
17
|
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export interface Options {
|
|
|
36
36
|
billTo?: string;
|
|
37
37
|
}
|
|
38
38
|
export type InferenceTask = Exclude<PipelineType, "other"> | "conversational";
|
|
39
|
-
export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "replicate", "sambanova", "scaleway", "together"];
|
|
40
|
-
export declare const PROVIDERS_OR_POLICIES: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "replicate", "sambanova", "scaleway", "together", "auto"];
|
|
39
|
+
export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "publicai", "replicate", "sambanova", "scaleway", "together", "zai-org"];
|
|
40
|
+
export declare const PROVIDERS_OR_POLICIES: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "featherless-ai", "fireworks-ai", "groq", "hf-inference", "hyperbolic", "nebius", "novita", "nscale", "openai", "ovhcloud", "publicai", "replicate", "sambanova", "scaleway", "together", "zai-org", "auto"];
|
|
41
41
|
export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
|
|
42
42
|
export type InferenceProviderOrPolicy = (typeof PROVIDERS_OR_POLICIES)[number];
|
|
43
43
|
export interface InferenceProviderMappingEntry {
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,MAAM;IACtB,K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AG,SAAS,CAAC;IACpD,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
|
package/dist/esm/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huggingface/inference",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
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,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@huggingface/tasks": "^0.19.
|
|
43
|
+
"@huggingface/tasks": "^0.19.48",
|
|
44
44
|
"@huggingface/jinja": "^0.5.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -12,6 +12,7 @@ import * as Novita from "../providers/novita.js";
|
|
|
12
12
|
import * as Nscale from "../providers/nscale.js";
|
|
13
13
|
import * as OpenAI from "../providers/openai.js";
|
|
14
14
|
import * as OvhCloud from "../providers/ovhcloud.js";
|
|
15
|
+
import * as PublicAI from "../providers/publicai.js";
|
|
15
16
|
import type {
|
|
16
17
|
AudioClassificationTaskHelper,
|
|
17
18
|
AudioToAudioTaskHelper,
|
|
@@ -49,6 +50,7 @@ import * as Replicate from "../providers/replicate.js";
|
|
|
49
50
|
import * as Sambanova from "../providers/sambanova.js";
|
|
50
51
|
import * as Scaleway from "../providers/scaleway.js";
|
|
51
52
|
import * as Together from "../providers/together.js";
|
|
53
|
+
import * as Zai from "../providers/zai-org.js";
|
|
52
54
|
import type { InferenceProvider, InferenceProviderOrPolicy, InferenceTask } from "../types.js";
|
|
53
55
|
import { InferenceClientInputError } from "../errors.js";
|
|
54
56
|
|
|
@@ -139,11 +141,15 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
|
|
|
139
141
|
conversational: new OvhCloud.OvhCloudConversationalTask(),
|
|
140
142
|
"text-generation": new OvhCloud.OvhCloudTextGenerationTask(),
|
|
141
143
|
},
|
|
144
|
+
publicai: {
|
|
145
|
+
conversational: new PublicAI.PublicAIConversationalTask(),
|
|
146
|
+
},
|
|
142
147
|
replicate: {
|
|
143
148
|
"text-to-image": new Replicate.ReplicateTextToImageTask(),
|
|
144
149
|
"text-to-speech": new Replicate.ReplicateTextToSpeechTask(),
|
|
145
150
|
"text-to-video": new Replicate.ReplicateTextToVideoTask(),
|
|
146
151
|
"image-to-image": new Replicate.ReplicateImageToImageTask(),
|
|
152
|
+
"automatic-speech-recognition": new Replicate.ReplicateAutomaticSpeechRecognitionTask(),
|
|
147
153
|
},
|
|
148
154
|
sambanova: {
|
|
149
155
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
@@ -159,6 +165,9 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
|
|
|
159
165
|
conversational: new Together.TogetherConversationalTask(),
|
|
160
166
|
"text-generation": new Together.TogetherTextGenerationTask(),
|
|
161
167
|
},
|
|
168
|
+
"zai-org": {
|
|
169
|
+
conversational: new Zai.ZaiConversationalTask(),
|
|
170
|
+
},
|
|
162
171
|
};
|
|
163
172
|
|
|
164
173
|
/**
|
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.
|
|
2
|
+
export const PACKAGE_VERSION = "4.9.0";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
package/src/providers/consts.ts
CHANGED
|
@@ -20,11 +20,14 @@ import type { BodyParams, HeaderParams, RequestArgs, UrlParams } from "../types.
|
|
|
20
20
|
import { omit } from "../utils/omit.js";
|
|
21
21
|
import {
|
|
22
22
|
TaskProviderHelper,
|
|
23
|
+
type AutomaticSpeechRecognitionTaskHelper,
|
|
23
24
|
type ImageToImageTaskHelper,
|
|
24
25
|
type TextToImageTaskHelper,
|
|
25
26
|
type TextToVideoTaskHelper,
|
|
26
27
|
} from "./providerHelper.js";
|
|
27
28
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
29
|
+
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition.js";
|
|
30
|
+
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
28
31
|
import { base64FromBytes } from "../utils/base64FromBytes.js";
|
|
29
32
|
export interface ReplicateOutput {
|
|
30
33
|
output?: string | string[];
|
|
@@ -163,6 +166,64 @@ export class ReplicateTextToVideoTask extends ReplicateTask implements TextToVid
|
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
export class ReplicateAutomaticSpeechRecognitionTask
|
|
170
|
+
extends ReplicateTask
|
|
171
|
+
implements AutomaticSpeechRecognitionTaskHelper
|
|
172
|
+
{
|
|
173
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
174
|
+
return {
|
|
175
|
+
input: {
|
|
176
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
177
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
178
|
+
audio: params.args.inputs, // This will be processed in preparePayloadAsync
|
|
179
|
+
},
|
|
180
|
+
version: params.model.includes(":") ? params.model.split(":")[1] : undefined,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async preparePayloadAsync(args: AutomaticSpeechRecognitionArgs): Promise<RequestArgs> {
|
|
185
|
+
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
186
|
+
|
|
187
|
+
if (!blob || !(blob instanceof Blob)) {
|
|
188
|
+
throw new Error("Audio input must be a Blob");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Convert Blob to base64 data URL
|
|
192
|
+
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
193
|
+
const base64 = base64FromBytes(bytes);
|
|
194
|
+
const audioInput = `data:${blob.type || "audio/wav"};base64,${base64}`;
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
...("data" in args ? omit(args, "data") : omit(args, "inputs")),
|
|
198
|
+
inputs: audioInput,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
override async getResponse(response: ReplicateOutput): Promise<AutomaticSpeechRecognitionOutput> {
|
|
203
|
+
if (typeof response?.output === "string") return { text: response.output };
|
|
204
|
+
if (Array.isArray(response?.output) && typeof response.output[0] === "string") return { text: response.output[0] };
|
|
205
|
+
|
|
206
|
+
const out = response?.output as
|
|
207
|
+
| undefined
|
|
208
|
+
| {
|
|
209
|
+
transcription?: string;
|
|
210
|
+
translation?: string;
|
|
211
|
+
txt_file?: string;
|
|
212
|
+
};
|
|
213
|
+
if (out && typeof out === "object") {
|
|
214
|
+
if (typeof out.transcription === "string") return { text: out.transcription };
|
|
215
|
+
if (typeof out.translation === "string") return { text: out.translation };
|
|
216
|
+
if (typeof out.txt_file === "string") {
|
|
217
|
+
const r = await fetch(out.txt_file);
|
|
218
|
+
return { text: await r.text() };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
throw new InferenceClientProviderOutputError(
|
|
222
|
+
"Received malformed response from Replicate automatic-speech-recognition API"
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
166
227
|
export class ReplicateImageToImageTask extends ReplicateTask implements ImageToImageTaskHelper {
|
|
167
228
|
override preparePayload(params: BodyParams<ImageToImageArgs>): Record<string, unknown> {
|
|
168
229
|
return {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => ZAI model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/zai-org/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 zai 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 zai, please open an issue on the present repo
|
|
13
|
+
* and we will tag zai team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper.js";
|
|
18
|
+
import type { HeaderParams } from "../types.js";
|
|
19
|
+
|
|
20
|
+
const ZAI_API_BASE_URL = "https://api.z.ai";
|
|
21
|
+
|
|
22
|
+
export class ZaiConversationalTask extends BaseConversationalTask {
|
|
23
|
+
constructor() {
|
|
24
|
+
super("zai-org", ZAI_API_BASE_URL);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override prepareHeaders(params: HeaderParams, binary: boolean): Record<string, string> {
|
|
28
|
+
const headers = super.prepareHeaders(params, binary);
|
|
29
|
+
headers["x-source-channel"] = "hugging_face";
|
|
30
|
+
headers["accept-language"] = "en-US,en";
|
|
31
|
+
return headers;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override makeRoute(): string {
|
|
35
|
+
return "/api/paas/v4/chat/completions";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -4,7 +4,6 @@ import { getProviderHelper } from "../../lib/getProviderHelper.js";
|
|
|
4
4
|
import type { BaseArgs, Options } from "../../types.js";
|
|
5
5
|
import { innerRequest } from "../../utils/request.js";
|
|
6
6
|
import type { LegacyAudioInput } from "./utils.js";
|
|
7
|
-
import { InferenceClientProviderOutputError } from "../../errors.js";
|
|
8
7
|
|
|
9
8
|
export type AutomaticSpeechRecognitionArgs = BaseArgs & (AutomaticSpeechRecognitionInput | LegacyAudioInput);
|
|
10
9
|
/**
|
|
@@ -22,9 +21,5 @@ export async function automaticSpeechRecognition(
|
|
|
22
21
|
...options,
|
|
23
22
|
task: "automatic-speech-recognition",
|
|
24
23
|
});
|
|
25
|
-
const isValidOutput = typeof res?.text === "string";
|
|
26
|
-
if (!isValidOutput) {
|
|
27
|
-
throw new InferenceClientProviderOutputError("Received malformed response from automatic-speech-recognition API");
|
|
28
|
-
}
|
|
29
24
|
return providerHelper.getResponse(res);
|
|
30
25
|
}
|
package/src/types.ts
CHANGED
|
@@ -59,10 +59,12 @@ export const INFERENCE_PROVIDERS = [
|
|
|
59
59
|
"nscale",
|
|
60
60
|
"openai",
|
|
61
61
|
"ovhcloud",
|
|
62
|
+
"publicai",
|
|
62
63
|
"replicate",
|
|
63
64
|
"sambanova",
|
|
64
65
|
"scaleway",
|
|
65
66
|
"together",
|
|
67
|
+
"zai-org",
|
|
66
68
|
] as const;
|
|
67
69
|
|
|
68
70
|
export const PROVIDERS_OR_POLICIES = [...INFERENCE_PROVIDERS, "auto"] as const;
|