@huggingface/inference 4.6.1 → 4.7.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 +2 -0
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +6 -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 +1 -0
- package/dist/commonjs/providers/scaleway.d.ts +41 -0
- package/dist/commonjs/providers/scaleway.d.ts.map +1 -0
- package/dist/commonjs/providers/scaleway.js +62 -0
- package/dist/commonjs/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +1 -0
- package/dist/commonjs/snippets/templates.exported.d.ts.map +1 -1
- package/dist/commonjs/snippets/templates.exported.js +7 -2
- package/dist/commonjs/types.d.ts +2 -2
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +1 -0
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +6 -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 +1 -0
- package/dist/esm/providers/scaleway.d.ts +41 -0
- package/dist/esm/providers/scaleway.d.ts.map +1 -0
- package/dist/esm/providers/scaleway.js +56 -0
- package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/esm/snippets/getInferenceSnippets.js +1 -0
- package/dist/esm/snippets/templates.exported.d.ts.map +1 -1
- package/dist/esm/snippets/templates.exported.js +7 -2
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -0
- package/package.json +2 -2
- package/src/lib/getProviderHelper.ts +6 -0
- package/src/package.ts +1 -1
- package/src/providers/consts.ts +1 -0
- package/src/providers/scaleway.ts +95 -0
- package/src/snippets/getInferenceSnippets.ts +1 -0
- package/src/snippets/templates.exported.ts +7 -2
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ Currently, we support the following providers:
|
|
|
58
58
|
- [OVHcloud](https://endpoints.ai.cloud.ovh.net/)
|
|
59
59
|
- [Replicate](https://replicate.com)
|
|
60
60
|
- [Sambanova](https://sambanova.ai)
|
|
61
|
+
- [Scaleway](https://www.scaleway.com/en/generative-apis/)
|
|
61
62
|
- [Together](https://together.xyz)
|
|
62
63
|
- [Blackforestlabs](https://blackforestlabs.ai)
|
|
63
64
|
- [Cohere](https://cohere.com)
|
|
@@ -92,6 +93,7 @@ Only a subset of models are supported when requesting third-party providers. You
|
|
|
92
93
|
- [OVHcloud supported models](https://huggingface.co/api/partners/ovhcloud/models)
|
|
93
94
|
- [Replicate supported models](https://huggingface.co/api/partners/replicate/models)
|
|
94
95
|
- [Sambanova supported models](https://huggingface.co/api/partners/sambanova/models)
|
|
96
|
+
- [Scaleway supported models](https://huggingface.co/api/partners/scaleway/models)
|
|
95
97
|
- [Together supported models](https://huggingface.co/api/partners/together/models)
|
|
96
98
|
- [Cohere supported models](https://huggingface.co/api/partners/cohere/models)
|
|
97
99
|
- [Cerebras supported models](https://huggingface.co/api/partners/cerebras/models)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAcA,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;
|
|
1
|
+
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAcA,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;AAKxC,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,CA2GnG,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,EACnC,IAAI,EAAE,gBAAgB,GACpB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AC9B,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"}
|
|
@@ -51,6 +51,7 @@ const OpenAI = __importStar(require("../providers/openai.js"));
|
|
|
51
51
|
const OvhCloud = __importStar(require("../providers/ovhcloud.js"));
|
|
52
52
|
const Replicate = __importStar(require("../providers/replicate.js"));
|
|
53
53
|
const Sambanova = __importStar(require("../providers/sambanova.js"));
|
|
54
|
+
const Scaleway = __importStar(require("../providers/scaleway.js"));
|
|
54
55
|
const Together = __importStar(require("../providers/together.js"));
|
|
55
56
|
const errors_js_1 = require("../errors.js");
|
|
56
57
|
exports.PROVIDERS = {
|
|
@@ -150,6 +151,11 @@ exports.PROVIDERS = {
|
|
|
150
151
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
151
152
|
"feature-extraction": new Sambanova.SambanovaFeatureExtractionTask(),
|
|
152
153
|
},
|
|
154
|
+
scaleway: {
|
|
155
|
+
conversational: new Scaleway.ScalewayConversationalTask(),
|
|
156
|
+
"text-generation": new Scaleway.ScalewayTextGenerationTask(),
|
|
157
|
+
"feature-extraction": new Scaleway.ScalewayFeatureExtractionTask(),
|
|
158
|
+
},
|
|
153
159
|
together: {
|
|
154
160
|
"text-to-image": new Together.TogetherTextToImageTask(),
|
|
155
161
|
conversational: new Together.TogetherConversationalTask(),
|
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.7.1";
|
|
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,CA0B9C,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => Scaleway model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/scaleway/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 Scaleway 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 Scaleway, please open an issue on the present repo
|
|
13
|
+
* and we will tag Scaleway team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import type { FeatureExtractionOutput, TextGenerationOutput } from "@huggingface/tasks";
|
|
18
|
+
import type { BodyParams } from "../types.js";
|
|
19
|
+
import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
|
|
20
|
+
import { BaseConversationalTask, TaskProviderHelper, BaseTextGenerationTask } from "./providerHelper.js";
|
|
21
|
+
interface ScalewayEmbeddingsResponse {
|
|
22
|
+
data: Array<{
|
|
23
|
+
embedding: number[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export declare class ScalewayConversationalTask extends BaseConversationalTask {
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
export declare class ScalewayTextGenerationTask extends BaseTextGenerationTask {
|
|
30
|
+
constructor();
|
|
31
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
32
|
+
getResponse(response: unknown): Promise<TextGenerationOutput>;
|
|
33
|
+
}
|
|
34
|
+
export declare class ScalewayFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
|
|
35
|
+
constructor();
|
|
36
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
37
|
+
makeRoute(): string;
|
|
38
|
+
getResponse(response: ScalewayEmbeddingsResponse): Promise<FeatureExtractionOutput>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=scaleway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaleway.d.ts","sourceRoot":"","sources":["../../../src/providers/scaleway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAIzG,UAAU,0BAA0B;IACnC,IAAI,EAAE,KAAK,CAAC;QACX,SAAS,EAAE,MAAM,EAAE,CAAC;KACpB,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,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAuB5E;AAED,qBAAa,6BAA8B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAK3G,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAO3D,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,0BAA0B,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAGzF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScalewayFeatureExtractionTask = exports.ScalewayTextGenerationTask = exports.ScalewayConversationalTask = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
6
|
+
const SCALEWAY_API_BASE_URL = "https://api.scaleway.ai";
|
|
7
|
+
class ScalewayConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ScalewayConversationalTask = ScalewayConversationalTask;
|
|
13
|
+
class ScalewayTextGenerationTask extends providerHelper_js_1.BaseTextGenerationTask {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
16
|
+
}
|
|
17
|
+
preparePayload(params) {
|
|
18
|
+
return {
|
|
19
|
+
model: params.model,
|
|
20
|
+
...params.args,
|
|
21
|
+
prompt: params.args.inputs,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async getResponse(response) {
|
|
25
|
+
if (typeof response === "object" &&
|
|
26
|
+
response !== null &&
|
|
27
|
+
"choices" in response &&
|
|
28
|
+
Array.isArray(response.choices) &&
|
|
29
|
+
response.choices.length > 0) {
|
|
30
|
+
const completion = response.choices[0];
|
|
31
|
+
if (typeof completion === "object" &&
|
|
32
|
+
!!completion &&
|
|
33
|
+
"text" in completion &&
|
|
34
|
+
completion.text &&
|
|
35
|
+
typeof completion.text === "string") {
|
|
36
|
+
return {
|
|
37
|
+
generated_text: completion.text,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw new errors_js_1.InferenceClientProviderOutputError("Received malformed response from Scaleway text generation API");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ScalewayTextGenerationTask = ScalewayTextGenerationTask;
|
|
45
|
+
class ScalewayFeatureExtractionTask extends providerHelper_js_1.TaskProviderHelper {
|
|
46
|
+
constructor() {
|
|
47
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
48
|
+
}
|
|
49
|
+
preparePayload(params) {
|
|
50
|
+
return {
|
|
51
|
+
input: params.args.inputs,
|
|
52
|
+
model: params.model,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
makeRoute() {
|
|
56
|
+
return "v1/embeddings";
|
|
57
|
+
}
|
|
58
|
+
async getResponse(response) {
|
|
59
|
+
return response.data.map((item) => item.embedding);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ScalewayFeatureExtractionTask = ScalewayFeatureExtractionTask;
|
|
@@ -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;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAKxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
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;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAKxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmY5B,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"}
|
|
@@ -278,6 +278,7 @@ const snippets = {
|
|
|
278
278
|
"image-text-to-text": snippetGenerator("conversational"),
|
|
279
279
|
"image-to-image": snippetGenerator("imageToImage", prepareImageToImageInput),
|
|
280
280
|
"image-to-text": snippetGenerator("basicImage"),
|
|
281
|
+
"image-to-video": snippetGenerator("imageToVideo", prepareImageToImageInput),
|
|
281
282
|
"object-detection": snippetGenerator("basicImage"),
|
|
282
283
|
"question-answering": snippetGenerator("questionAnswering", prepareQuestionAnsweringInput),
|
|
283
284
|
"sentence-similarity": snippetGenerator("basic"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.exported.d.ts","sourceRoot":"","sources":["../../../src/snippets/templates.exported.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"templates.exported.d.ts","sourceRoot":"","sources":["../../../src/snippets/templates.exported.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqFnE,CAAC"}
|
|
@@ -10,6 +10,7 @@ exports.templates = {
|
|
|
10
10
|
"basicImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
11
11
|
"conversational": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n{{ autoInputs.asTsString }}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
12
12
|
"imageToImage": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"inputs\": `data:image/png;base64,${data.inputs.encode(\"base64\")}`,\n\t\t\t\t\"parameters\": data.parameters,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n\tinputs: image,\n\tparameters: {\n\t\tprompt: \"{{ inputs.asObj.parameters.prompt }}\",\n\t}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
13
|
+
"imageToVideo": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"image_url\": `data:image/png;base64,${data.image.encode(\"base64\")}`,\n\t\t\t\t\"prompt\": data.prompt,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({\n\t\"image\": image,\n\t\"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n}).then((response) => {\n // Use video\n});",
|
|
13
14
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
14
15
|
"textToImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n\treturn result;\n}\n\n\nquery({ {{ providerInputs.asTsString }} }).then((response) => {\n // Use image\n});",
|
|
15
16
|
"textToSpeech": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
@@ -22,6 +23,7 @@ exports.templates = {
|
|
|
22
23
|
"conversational": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst chatCompletion = await client.chatCompletion({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
23
24
|
"conversationalStream": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nlet out = \"\";\n\nconst stream = client.chatCompletionStream({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nfor await (const chunk of stream) {\n\tif (chunk.choices && chunk.choices.length > 0) {\n\t\tconst newContent = chunk.choices[0].delta.content;\n\t\tout += newContent;\n\t\tconsole.log(newContent);\n\t}\n}",
|
|
24
25
|
"imageToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst image = await client.imageToImage({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)\n// For example, you can save it to a file or display it in an image element\n",
|
|
26
|
+
"imageToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst video = await client.imageToVideo({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\n/// Use the generated video (it's a Blob)\n// For example, you can save it to a file or display it in a video element\n",
|
|
25
27
|
"textToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst image = await client.textToImage({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tparameters: { num_inference_steps: 5 },\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)",
|
|
26
28
|
"textToSpeech": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst audio = await client.textToSpeech({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated audio (it's a Blob)",
|
|
27
29
|
"textToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst video = await client.textToVideo({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated video (it's a Blob)"
|
|
@@ -34,6 +36,7 @@ exports.templates = {
|
|
|
34
36
|
"python": {
|
|
35
37
|
"fal_client": {
|
|
36
38
|
"imageToImage": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"fal-ai/flux-kontext/dev\",\n arguments={\n \"prompt\": f\"data:image/png;base64,{image_base_64}\",\n \"image_url\": \"{{ providerInputs.asObj.inputs }}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
39
|
+
"imageToVideo": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"{{model.id}}\",\n arguments={\n \"image_url\": f\"data:image/png;base64,{image_base_64}\",\n \"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
37
40
|
"textToImage": "{% if provider == \"fal-ai\" %}\nimport fal_client\n\n{% if providerInputs.asObj.loras is defined and providerInputs.asObj.loras != none %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n \"loras\":{{ providerInputs.asObj.loras | tojson }},\n },\n)\n{% else %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n },\n)\n{% endif %} \nprint(result)\n{% endif %} "
|
|
38
41
|
},
|
|
39
42
|
"huggingface_hub": {
|
|
@@ -43,7 +46,8 @@ exports.templates = {
|
|
|
43
46
|
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
44
47
|
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
45
48
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
46
|
-
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)
|
|
49
|
+
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)\n",
|
|
50
|
+
"imageToVideo": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\nvideo = client.image_to_video(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n) \n",
|
|
47
51
|
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n provider=\"{{ provider }}\",\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
48
52
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
49
53
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -62,7 +66,8 @@ exports.templates = {
|
|
|
62
66
|
"conversational": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\nresponse = query({\n{{ autoInputs.asJsonString }}\n})\n\nprint(response[\"choices\"][0][\"message\"])",
|
|
63
67
|
"conversationalStream": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload, stream=True)\n for line in response.iter_lines():\n if not line.startswith(b\"data:\"):\n continue\n if line.strip() == b\"data: [DONE]\":\n return\n yield json.loads(line.decode(\"utf-8\").lstrip(\"data:\").rstrip(\"/n\"))\n\nchunks = query({\n{{ autoInputs.asJsonString }},\n \"stream\": True,\n})\n\nfor chunk in chunks:\n print(chunk[\"choices\"][0][\"delta\"][\"content\"], end=\"\")",
|
|
64
68
|
"documentQuestionAnswering": "def query(payload):\n with open(payload[\"image\"], \"rb\") as f:\n img = f.read()\n payload[\"image\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\noutput = query({\n \"inputs\": {\n \"image\": \"{{ inputs.asObj.image }}\",\n \"question\": \"{{ inputs.asObj.question }}\",\n },\n}) ",
|
|
65
|
-
"imageToImage": "
|
|
69
|
+
"imageToImage": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nimage_bytes = query({\n{{ providerInputs.asJsonString }}\n})\n\n# You can access the image with PIL.Image for example\nimport io\nfrom PIL import Image\nimage = Image.open(io.BytesIO(image_bytes)) ",
|
|
70
|
+
"imageToVideo": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nvideo_bytes = query({\n{{ inputs.asJsonString }}\n})\n",
|
|
66
71
|
"importRequests": "{% if importBase64 %}\nimport base64\n{% endif %}\n{% if importJson %}\nimport json\n{% endif %}\nimport requests\n\nAPI_URL = \"{{ fullUrl }}\"\nheaders = {\n \"Authorization\": \"{{ authorizationHeader }}\",\n{% if billTo %}\n \"X-HF-Bill-To\": \"{{ billTo }}\"\n{% endif %}\n}",
|
|
67
72
|
"tabular": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nresponse = query({\n \"inputs\": {\n \"data\": {{ providerInputs.asObj.inputs }}\n },\n}) ",
|
|
68
73
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\naudio_bytes = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio_bytes)\n{% else %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\naudio, sampling_rate = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio, rate=sampling_rate)\n{% endif %} ",
|
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", "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", "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", "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"];
|
|
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,GAAG,MAAM,CAAC;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ACd,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":"AAcA,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;
|
|
1
|
+
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAcA,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,E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AAgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GAAG,SAAS,GAC7B,kBAAkB,CAAC"}
|
|
@@ -14,6 +14,7 @@ import * as OpenAI from "../providers/openai.js";
|
|
|
14
14
|
import * as OvhCloud from "../providers/ovhcloud.js";
|
|
15
15
|
import * as Replicate from "../providers/replicate.js";
|
|
16
16
|
import * as Sambanova from "../providers/sambanova.js";
|
|
17
|
+
import * as Scaleway from "../providers/scaleway.js";
|
|
17
18
|
import * as Together from "../providers/together.js";
|
|
18
19
|
import { InferenceClientInputError } from "../errors.js";
|
|
19
20
|
export const PROVIDERS = {
|
|
@@ -113,6 +114,11 @@ export const PROVIDERS = {
|
|
|
113
114
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
114
115
|
"feature-extraction": new Sambanova.SambanovaFeatureExtractionTask(),
|
|
115
116
|
},
|
|
117
|
+
scaleway: {
|
|
118
|
+
conversational: new Scaleway.ScalewayConversationalTask(),
|
|
119
|
+
"text-generation": new Scaleway.ScalewayTextGenerationTask(),
|
|
120
|
+
"feature-extraction": new Scaleway.ScalewayFeatureExtractionTask(),
|
|
121
|
+
},
|
|
116
122
|
together: {
|
|
117
123
|
"text-to-image": new Together.TogetherTextToImageTask(),
|
|
118
124
|
conversational: new Together.TogetherConversationalTask(),
|
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.7.1";
|
|
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,CA0B9C,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => Scaleway model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/scaleway/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 Scaleway 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 Scaleway, please open an issue on the present repo
|
|
13
|
+
* and we will tag Scaleway team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import type { FeatureExtractionOutput, TextGenerationOutput } from "@huggingface/tasks";
|
|
18
|
+
import type { BodyParams } from "../types.js";
|
|
19
|
+
import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
|
|
20
|
+
import { BaseConversationalTask, TaskProviderHelper, BaseTextGenerationTask } from "./providerHelper.js";
|
|
21
|
+
interface ScalewayEmbeddingsResponse {
|
|
22
|
+
data: Array<{
|
|
23
|
+
embedding: number[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export declare class ScalewayConversationalTask extends BaseConversationalTask {
|
|
27
|
+
constructor();
|
|
28
|
+
}
|
|
29
|
+
export declare class ScalewayTextGenerationTask extends BaseTextGenerationTask {
|
|
30
|
+
constructor();
|
|
31
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
32
|
+
getResponse(response: unknown): Promise<TextGenerationOutput>;
|
|
33
|
+
}
|
|
34
|
+
export declare class ScalewayFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
|
|
35
|
+
constructor();
|
|
36
|
+
preparePayload(params: BodyParams): Record<string, unknown>;
|
|
37
|
+
makeRoute(): string;
|
|
38
|
+
getResponse(response: ScalewayEmbeddingsResponse): Promise<FeatureExtractionOutput>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=scaleway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaleway.d.ts","sourceRoot":"","sources":["../../../src/providers/scaleway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAIzG,UAAU,0BAA0B;IACnC,IAAI,EAAE,KAAK,CAAC;QACX,SAAS,EAAE,MAAM,EAAE,CAAC;KACpB,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,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAuB5E;AAED,qBAAa,6BAA8B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAK3G,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAO3D,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,0BAA0B,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAGzF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
2
|
+
import { BaseConversationalTask, TaskProviderHelper, BaseTextGenerationTask } from "./providerHelper.js";
|
|
3
|
+
const SCALEWAY_API_BASE_URL = "https://api.scaleway.ai";
|
|
4
|
+
export class ScalewayConversationalTask extends BaseConversationalTask {
|
|
5
|
+
constructor() {
|
|
6
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class ScalewayTextGenerationTask extends BaseTextGenerationTask {
|
|
10
|
+
constructor() {
|
|
11
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
12
|
+
}
|
|
13
|
+
preparePayload(params) {
|
|
14
|
+
return {
|
|
15
|
+
model: params.model,
|
|
16
|
+
...params.args,
|
|
17
|
+
prompt: params.args.inputs,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async getResponse(response) {
|
|
21
|
+
if (typeof response === "object" &&
|
|
22
|
+
response !== null &&
|
|
23
|
+
"choices" in response &&
|
|
24
|
+
Array.isArray(response.choices) &&
|
|
25
|
+
response.choices.length > 0) {
|
|
26
|
+
const completion = response.choices[0];
|
|
27
|
+
if (typeof completion === "object" &&
|
|
28
|
+
!!completion &&
|
|
29
|
+
"text" in completion &&
|
|
30
|
+
completion.text &&
|
|
31
|
+
typeof completion.text === "string") {
|
|
32
|
+
return {
|
|
33
|
+
generated_text: completion.text,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Scaleway text generation API");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class ScalewayFeatureExtractionTask extends TaskProviderHelper {
|
|
41
|
+
constructor() {
|
|
42
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
43
|
+
}
|
|
44
|
+
preparePayload(params) {
|
|
45
|
+
return {
|
|
46
|
+
input: params.args.inputs,
|
|
47
|
+
model: params.model,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
makeRoute() {
|
|
51
|
+
return "v1/embeddings";
|
|
52
|
+
}
|
|
53
|
+
async getResponse(response) {
|
|
54
|
+
return response.data.map((item) => item.embedding);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -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;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAKxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;
|
|
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;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAKxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmY5B,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"}
|
|
@@ -275,6 +275,7 @@ const snippets = {
|
|
|
275
275
|
"image-text-to-text": snippetGenerator("conversational"),
|
|
276
276
|
"image-to-image": snippetGenerator("imageToImage", prepareImageToImageInput),
|
|
277
277
|
"image-to-text": snippetGenerator("basicImage"),
|
|
278
|
+
"image-to-video": snippetGenerator("imageToVideo", prepareImageToImageInput),
|
|
278
279
|
"object-detection": snippetGenerator("basicImage"),
|
|
279
280
|
"question-answering": snippetGenerator("questionAnswering", prepareQuestionAnsweringInput),
|
|
280
281
|
"sentence-similarity": snippetGenerator("basic"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.exported.d.ts","sourceRoot":"","sources":["../../../src/snippets/templates.exported.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"templates.exported.d.ts","sourceRoot":"","sources":["../../../src/snippets/templates.exported.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAqFnE,CAAC"}
|
|
@@ -7,6 +7,7 @@ export const templates = {
|
|
|
7
7
|
"basicImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
8
8
|
"conversational": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n{{ autoInputs.asTsString }}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
9
9
|
"imageToImage": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"inputs\": `data:image/png;base64,${data.inputs.encode(\"base64\")}`,\n\t\t\t\t\"parameters\": data.parameters,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n\tinputs: image,\n\tparameters: {\n\t\tprompt: \"{{ inputs.asObj.parameters.prompt }}\",\n\t}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
10
|
+
"imageToVideo": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"image_url\": `data:image/png;base64,${data.image.encode(\"base64\")}`,\n\t\t\t\t\"prompt\": data.prompt,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({\n\t\"image\": image,\n\t\"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n}).then((response) => {\n // Use video\n});",
|
|
10
11
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
11
12
|
"textToImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n\treturn result;\n}\n\n\nquery({ {{ providerInputs.asTsString }} }).then((response) => {\n // Use image\n});",
|
|
12
13
|
"textToSpeech": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
@@ -19,6 +20,7 @@ export const templates = {
|
|
|
19
20
|
"conversational": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst chatCompletion = await client.chatCompletion({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
20
21
|
"conversationalStream": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nlet out = \"\";\n\nconst stream = client.chatCompletionStream({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nfor await (const chunk of stream) {\n\tif (chunk.choices && chunk.choices.length > 0) {\n\t\tconst newContent = chunk.choices[0].delta.content;\n\t\tout += newContent;\n\t\tconsole.log(newContent);\n\t}\n}",
|
|
21
22
|
"imageToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst image = await client.imageToImage({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)\n// For example, you can save it to a file or display it in an image element\n",
|
|
23
|
+
"imageToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst video = await client.imageToVideo({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\n/// Use the generated video (it's a Blob)\n// For example, you can save it to a file or display it in a video element\n",
|
|
22
24
|
"textToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst image = await client.textToImage({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tparameters: { num_inference_steps: 5 },\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)",
|
|
23
25
|
"textToSpeech": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst audio = await client.textToSpeech({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated audio (it's a Blob)",
|
|
24
26
|
"textToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst video = await client.textToVideo({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated video (it's a Blob)"
|
|
@@ -31,6 +33,7 @@ export const templates = {
|
|
|
31
33
|
"python": {
|
|
32
34
|
"fal_client": {
|
|
33
35
|
"imageToImage": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"fal-ai/flux-kontext/dev\",\n arguments={\n \"prompt\": f\"data:image/png;base64,{image_base_64}\",\n \"image_url\": \"{{ providerInputs.asObj.inputs }}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
36
|
+
"imageToVideo": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"{{model.id}}\",\n arguments={\n \"image_url\": f\"data:image/png;base64,{image_base_64}\",\n \"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
34
37
|
"textToImage": "{% if provider == \"fal-ai\" %}\nimport fal_client\n\n{% if providerInputs.asObj.loras is defined and providerInputs.asObj.loras != none %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n \"loras\":{{ providerInputs.asObj.loras | tojson }},\n },\n)\n{% else %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n },\n)\n{% endif %} \nprint(result)\n{% endif %} "
|
|
35
38
|
},
|
|
36
39
|
"huggingface_hub": {
|
|
@@ -40,7 +43,8 @@ export const templates = {
|
|
|
40
43
|
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
41
44
|
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
42
45
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
43
|
-
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)
|
|
46
|
+
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)\n",
|
|
47
|
+
"imageToVideo": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\nvideo = client.image_to_video(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n) \n",
|
|
44
48
|
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n provider=\"{{ provider }}\",\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
45
49
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
46
50
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -59,7 +63,8 @@ export const templates = {
|
|
|
59
63
|
"conversational": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\nresponse = query({\n{{ autoInputs.asJsonString }}\n})\n\nprint(response[\"choices\"][0][\"message\"])",
|
|
60
64
|
"conversationalStream": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload, stream=True)\n for line in response.iter_lines():\n if not line.startswith(b\"data:\"):\n continue\n if line.strip() == b\"data: [DONE]\":\n return\n yield json.loads(line.decode(\"utf-8\").lstrip(\"data:\").rstrip(\"/n\"))\n\nchunks = query({\n{{ autoInputs.asJsonString }},\n \"stream\": True,\n})\n\nfor chunk in chunks:\n print(chunk[\"choices\"][0][\"delta\"][\"content\"], end=\"\")",
|
|
61
65
|
"documentQuestionAnswering": "def query(payload):\n with open(payload[\"image\"], \"rb\") as f:\n img = f.read()\n payload[\"image\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\noutput = query({\n \"inputs\": {\n \"image\": \"{{ inputs.asObj.image }}\",\n \"question\": \"{{ inputs.asObj.question }}\",\n },\n}) ",
|
|
62
|
-
"imageToImage": "
|
|
66
|
+
"imageToImage": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nimage_bytes = query({\n{{ providerInputs.asJsonString }}\n})\n\n# You can access the image with PIL.Image for example\nimport io\nfrom PIL import Image\nimage = Image.open(io.BytesIO(image_bytes)) ",
|
|
67
|
+
"imageToVideo": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nvideo_bytes = query({\n{{ inputs.asJsonString }}\n})\n",
|
|
63
68
|
"importRequests": "{% if importBase64 %}\nimport base64\n{% endif %}\n{% if importJson %}\nimport json\n{% endif %}\nimport requests\n\nAPI_URL = \"{{ fullUrl }}\"\nheaders = {\n \"Authorization\": \"{{ authorizationHeader }}\",\n{% if billTo %}\n \"X-HF-Bill-To\": \"{{ billTo }}\"\n{% endif %}\n}",
|
|
64
69
|
"tabular": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nresponse = query({\n \"inputs\": {\n \"data\": {{ providerInputs.asObj.inputs }}\n },\n}) ",
|
|
65
70
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\naudio_bytes = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio_bytes)\n{% else %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\naudio, sampling_rate = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio, rate=sampling_rate)\n{% endif %} ",
|
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", "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", "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", "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"];
|
|
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,OA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C,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,6BAA6B,GAAG,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.7.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Hugging Face and Tim Mikeladze <tim.mikeladze@gmail.com>",
|
|
6
6
|
"description": "Typescript client for the Hugging Face Inference Providers and Inference Endpoints",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@huggingface/tasks": "^0.19.
|
|
43
|
+
"@huggingface/tasks": "^0.19.35",
|
|
44
44
|
"@huggingface/jinja": "^0.5.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -47,6 +47,7 @@ import type {
|
|
|
47
47
|
} from "../providers/providerHelper.js";
|
|
48
48
|
import * as Replicate from "../providers/replicate.js";
|
|
49
49
|
import * as Sambanova from "../providers/sambanova.js";
|
|
50
|
+
import * as Scaleway from "../providers/scaleway.js";
|
|
50
51
|
import * as Together from "../providers/together.js";
|
|
51
52
|
import type { InferenceProvider, InferenceProviderOrPolicy, InferenceTask } from "../types.js";
|
|
52
53
|
import { InferenceClientInputError } from "../errors.js";
|
|
@@ -148,6 +149,11 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
|
|
|
148
149
|
conversational: new Sambanova.SambanovaConversationalTask(),
|
|
149
150
|
"feature-extraction": new Sambanova.SambanovaFeatureExtractionTask(),
|
|
150
151
|
},
|
|
152
|
+
scaleway: {
|
|
153
|
+
conversational: new Scaleway.ScalewayConversationalTask(),
|
|
154
|
+
"text-generation": new Scaleway.ScalewayTextGenerationTask(),
|
|
155
|
+
"feature-extraction": new Scaleway.ScalewayFeatureExtractionTask(),
|
|
156
|
+
},
|
|
151
157
|
together: {
|
|
152
158
|
"text-to-image": new Together.TogetherTextToImageTask(),
|
|
153
159
|
conversational: new Together.TogetherConversationalTask(),
|
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.7.1";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
package/src/providers/consts.ts
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See the registered mapping of HF model ID => Scaleway model ID here:
|
|
3
|
+
*
|
|
4
|
+
* https://huggingface.co/api/partners/scaleway/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 Scaleway 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 Scaleway, please open an issue on the present repo
|
|
13
|
+
* and we will tag Scaleway team members.
|
|
14
|
+
*
|
|
15
|
+
* Thanks!
|
|
16
|
+
*/
|
|
17
|
+
import type { FeatureExtractionOutput, TextGenerationOutput } from "@huggingface/tasks";
|
|
18
|
+
import type { BodyParams } from "../types.js";
|
|
19
|
+
import { InferenceClientProviderOutputError } from "../errors.js";
|
|
20
|
+
|
|
21
|
+
import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
|
|
22
|
+
import { BaseConversationalTask, TaskProviderHelper, BaseTextGenerationTask } from "./providerHelper.js";
|
|
23
|
+
|
|
24
|
+
const SCALEWAY_API_BASE_URL = "https://api.scaleway.ai";
|
|
25
|
+
|
|
26
|
+
interface ScalewayEmbeddingsResponse {
|
|
27
|
+
data: Array<{
|
|
28
|
+
embedding: number[];
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class ScalewayConversationalTask extends BaseConversationalTask {
|
|
33
|
+
constructor() {
|
|
34
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class ScalewayTextGenerationTask extends BaseTextGenerationTask {
|
|
39
|
+
constructor() {
|
|
40
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
44
|
+
return {
|
|
45
|
+
model: params.model,
|
|
46
|
+
...params.args,
|
|
47
|
+
prompt: params.args.inputs,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override async getResponse(response: unknown): Promise<TextGenerationOutput> {
|
|
52
|
+
if (
|
|
53
|
+
typeof response === "object" &&
|
|
54
|
+
response !== null &&
|
|
55
|
+
"choices" in response &&
|
|
56
|
+
Array.isArray(response.choices) &&
|
|
57
|
+
response.choices.length > 0
|
|
58
|
+
) {
|
|
59
|
+
const completion: unknown = response.choices[0];
|
|
60
|
+
if (
|
|
61
|
+
typeof completion === "object" &&
|
|
62
|
+
!!completion &&
|
|
63
|
+
"text" in completion &&
|
|
64
|
+
completion.text &&
|
|
65
|
+
typeof completion.text === "string"
|
|
66
|
+
) {
|
|
67
|
+
return {
|
|
68
|
+
generated_text: completion.text,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new InferenceClientProviderOutputError("Received malformed response from Scaleway text generation API");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class ScalewayFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
|
|
77
|
+
constructor() {
|
|
78
|
+
super("scaleway", SCALEWAY_API_BASE_URL);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
82
|
+
return {
|
|
83
|
+
input: params.args.inputs,
|
|
84
|
+
model: params.model,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
makeRoute(): string {
|
|
89
|
+
return "v1/embeddings";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getResponse(response: ScalewayEmbeddingsResponse): Promise<FeatureExtractionOutput> {
|
|
93
|
+
return response.data.map((item) => item.embedding);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -389,6 +389,7 @@ const snippets: Partial<
|
|
|
389
389
|
"image-text-to-text": snippetGenerator("conversational"),
|
|
390
390
|
"image-to-image": snippetGenerator("imageToImage", prepareImageToImageInput),
|
|
391
391
|
"image-to-text": snippetGenerator("basicImage"),
|
|
392
|
+
"image-to-video": snippetGenerator("imageToVideo", prepareImageToImageInput),
|
|
392
393
|
"object-detection": snippetGenerator("basicImage"),
|
|
393
394
|
"question-answering": snippetGenerator("questionAnswering", prepareQuestionAnsweringInput),
|
|
394
395
|
"sentence-similarity": snippetGenerator("basic"),
|
|
@@ -7,6 +7,7 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
7
7
|
"basicImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
8
8
|
"conversational": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n{{ autoInputs.asTsString }}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
9
9
|
"imageToImage": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"inputs\": `data:image/png;base64,${data.inputs.encode(\"base64\")}`,\n\t\t\t\t\"parameters\": data.parameters,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({ \n\tinputs: image,\n\tparameters: {\n\t\tprompt: \"{{ inputs.asObj.parameters.prompt }}\",\n\t}\n}).then((response) => {\n console.log(JSON.stringify(response));\n});",
|
|
10
|
+
"imageToVideo": "const image = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"image/jpeg\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\t\"image_url\": `data:image/png;base64,${data.image.encode(\"base64\")}`,\n\t\t\t\t\"prompt\": data.prompt,\n\t\t\t}\n\t\t}\n\t);\n\tconst result = await response.json();\n\treturn result;\n}\n\nquery({\n\t\"image\": image,\n\t\"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n}).then((response) => {\n // Use video\n});",
|
|
10
11
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
11
12
|
"textToImage": "async function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n\treturn result;\n}\n\n\nquery({ {{ providerInputs.asTsString }} }).then((response) => {\n // Use image\n});",
|
|
12
13
|
"textToSpeech": "{% if model.library_name == \"transformers\" %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n{% if billTo %}\n\t\t\t\t\"X-HF-Bill-To\": \"{{ billTo }}\",\n{% endif %}\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n\tconst result = await response.blob();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n // Returns a byte object of the Audio wavform. Use it directly!\n});\n{% else %}\nasync function query(data) {\n\tconst response = await fetch(\n\t\t\"{{ fullUrl }}\",\n\t\t{\n\t\t\theaders: {\n\t\t\t\tAuthorization: \"{{ authorizationHeader }}\",\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t},\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify(data),\n\t\t}\n\t);\n const result = await response.json();\n return result;\n}\n\nquery({ text: {{ inputs.asObj.inputs }} }).then((response) => {\n console.log(JSON.stringify(response));\n});\n{% endif %} ",
|
|
@@ -19,6 +20,7 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
19
20
|
"conversational": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst chatCompletion = await client.chatCompletion({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
20
21
|
"conversationalStream": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nlet out = \"\";\n\nconst stream = client.chatCompletionStream({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nfor await (const chunk of stream) {\n\tif (chunk.choices && chunk.choices.length > 0) {\n\t\tconst newContent = chunk.choices[0].delta.content;\n\t\tout += newContent;\n\t\tconsole.log(newContent);\n\t}\n}",
|
|
21
22
|
"imageToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst image = await client.imageToImage({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)\n// For example, you can save it to a file or display it in an image element\n",
|
|
23
|
+
"imageToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync(\"{{inputs.asObj.inputs}}\");\n\nconst video = await client.imageToVideo({\n{% if endpointUrl %}\n\tendpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tprovider: \"{{provider}}\",\n\tmodel: \"{{model.id}}\",\n\tinputs: data,\n\tparameters: { prompt: \"{{inputs.asObj.parameters.prompt}}\", },\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\n/// Use the generated video (it's a Blob)\n// For example, you can save it to a file or display it in a video element\n",
|
|
22
24
|
"textToImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst image = await client.textToImage({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tparameters: { num_inference_steps: 5 },\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n/// Use the generated image (it's a Blob)",
|
|
23
25
|
"textToSpeech": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst audio = await client.textToSpeech({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated audio (it's a Blob)",
|
|
24
26
|
"textToVideo": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst video = await client.textToVideo({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n// Use the generated video (it's a Blob)"
|
|
@@ -31,6 +33,7 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
31
33
|
"python": {
|
|
32
34
|
"fal_client": {
|
|
33
35
|
"imageToImage": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"fal-ai/flux-kontext/dev\",\n arguments={\n \"prompt\": f\"data:image/png;base64,{image_base_64}\",\n \"image_url\": \"{{ providerInputs.asObj.inputs }}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
36
|
+
"imageToVideo": "{%if provider == \"fal-ai\" %}\nimport fal_client\nimport base64\n\ndef on_queue_update(update):\n if isinstance(update, fal_client.InProgress):\n for log in update.logs:\n print(log[\"message\"])\n\nwith open(\"{{inputs.asObj.inputs}}\", \"rb\") as image_file:\n image_base_64 = base64.b64encode(image_file.read()).decode('utf-8')\n\nresult = fal_client.subscribe(\n \"{{model.id}}\",\n arguments={\n \"image_url\": f\"data:image/png;base64,{image_base_64}\",\n \"prompt\": \"{{inputs.asObj.parameters.prompt}}\",\n },\n with_logs=True,\n on_queue_update=on_queue_update,\n)\nprint(result)\n{%endif%}\n",
|
|
34
37
|
"textToImage": "{% if provider == \"fal-ai\" %}\nimport fal_client\n\n{% if providerInputs.asObj.loras is defined and providerInputs.asObj.loras != none %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n \"loras\":{{ providerInputs.asObj.loras | tojson }},\n },\n)\n{% else %}\nresult = fal_client.subscribe(\n \"{{ providerModelId }}\",\n arguments={\n \"prompt\": {{ inputs.asObj.inputs }},\n },\n)\n{% endif %} \nprint(result)\n{% endif %} "
|
|
35
38
|
},
|
|
36
39
|
"huggingface_hub": {
|
|
@@ -40,7 +43,8 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
40
43
|
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
41
44
|
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
42
45
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
43
|
-
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)
|
|
46
|
+
"imageToImage": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\n# output is a PIL.Image object\nimage = client.image_to_image(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n)\n",
|
|
47
|
+
"imageToVideo": "with open(\"{{ inputs.asObj.inputs }}\", \"rb\") as image_file:\n input_image = image_file.read()\n\nvideo = client.image_to_video(\n input_image,\n prompt=\"{{ inputs.asObj.parameters.prompt }}\",\n model=\"{{ model.id }}\",\n) \n",
|
|
44
48
|
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n provider=\"{{ provider }}\",\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
45
49
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
46
50
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -59,7 +63,8 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
59
63
|
"conversational": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\nresponse = query({\n{{ autoInputs.asJsonString }}\n})\n\nprint(response[\"choices\"][0][\"message\"])",
|
|
60
64
|
"conversationalStream": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload, stream=True)\n for line in response.iter_lines():\n if not line.startswith(b\"data:\"):\n continue\n if line.strip() == b\"data: [DONE]\":\n return\n yield json.loads(line.decode(\"utf-8\").lstrip(\"data:\").rstrip(\"/n\"))\n\nchunks = query({\n{{ autoInputs.asJsonString }},\n \"stream\": True,\n})\n\nfor chunk in chunks:\n print(chunk[\"choices\"][0][\"delta\"][\"content\"], end=\"\")",
|
|
61
65
|
"documentQuestionAnswering": "def query(payload):\n with open(payload[\"image\"], \"rb\") as f:\n img = f.read()\n payload[\"image\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\noutput = query({\n \"inputs\": {\n \"image\": \"{{ inputs.asObj.image }}\",\n \"question\": \"{{ inputs.asObj.question }}\",\n },\n}) ",
|
|
62
|
-
"imageToImage": "
|
|
66
|
+
"imageToImage": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nimage_bytes = query({\n{{ providerInputs.asJsonString }}\n})\n\n# You can access the image with PIL.Image for example\nimport io\nfrom PIL import Image\nimage = Image.open(io.BytesIO(image_bytes)) ",
|
|
67
|
+
"imageToVideo": "\ndef query(payload):\n with open(payload[\"inputs\"], \"rb\") as f:\n img = f.read()\n payload[\"inputs\"] = base64.b64encode(img).decode(\"utf-8\")\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nvideo_bytes = query({\n{{ inputs.asJsonString }}\n})\n",
|
|
63
68
|
"importRequests": "{% if importBase64 %}\nimport base64\n{% endif %}\n{% if importJson %}\nimport json\n{% endif %}\nimport requests\n\nAPI_URL = \"{{ fullUrl }}\"\nheaders = {\n \"Authorization\": \"{{ authorizationHeader }}\",\n{% if billTo %}\n \"X-HF-Bill-To\": \"{{ billTo }}\"\n{% endif %}\n}",
|
|
64
69
|
"tabular": "def query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\nresponse = query({\n \"inputs\": {\n \"data\": {{ providerInputs.asObj.inputs }}\n },\n}) ",
|
|
65
70
|
"textToAudio": "{% if model.library_name == \"transformers\" %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.content\n\naudio_bytes = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio_bytes)\n{% else %}\ndef query(payload):\n response = requests.post(API_URL, headers=headers, json=payload)\n return response.json()\n\naudio, sampling_rate = query({\n \"inputs\": {{ inputs.asObj.inputs }},\n})\n# You can access the audio with IPython.display for example\nfrom IPython.display import Audio\nAudio(audio, rate=sampling_rate)\n{% endif %} ",
|