@huggingface/inference 4.12.0 → 4.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +1 -0
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/wavespeed.d.ts +7 -2
- package/dist/commonjs/providers/wavespeed.d.ts.map +1 -1
- package/dist/commonjs/providers/wavespeed.js +20 -3
- package/dist/commonjs/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +2 -0
- package/dist/commonjs/snippets/templates.exported.js +5 -5
- package/dist/commonjs/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/chatCompletionStream.js +10 -2
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/esm/lib/getProviderHelper.js +1 -0
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/wavespeed.d.ts +7 -2
- package/dist/esm/providers/wavespeed.d.ts.map +1 -1
- package/dist/esm/providers/wavespeed.js +18 -2
- package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/esm/snippets/getInferenceSnippets.js +2 -0
- package/dist/esm/snippets/templates.exported.js +5 -5
- package/dist/esm/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
- package/dist/esm/tasks/nlp/chatCompletionStream.js +10 -2
- package/package.json +2 -2
- package/src/lib/getProviderHelper.ts +1 -0
- package/src/package.ts +1 -1
- package/src/providers/wavespeed.ts +34 -4
- package/src/snippets/getInferenceSnippets.ts +4 -0
- package/src/snippets/templates.exported.ts +5 -5
- package/src/tasks/nlp/chatCompletionStream.ts +10 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAiBA,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;AAOxC,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,
|
|
1
|
+
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAiBA,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,EAC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AgB,iBAAiB,CAChC,QAAQ,EAAE,yBAAyB,EACnC,IAAI,EAAE,aAAa,GAAG,SAAS,GAC7B,kBAAkB,CAAC"}
|
|
@@ -180,6 +180,7 @@ exports.PROVIDERS = {
|
|
|
180
180
|
"text-to-image": new Wavespeed.WavespeedAITextToImageTask(),
|
|
181
181
|
"text-to-video": new Wavespeed.WavespeedAITextToVideoTask(),
|
|
182
182
|
"image-to-image": new Wavespeed.WavespeedAIImageToImageTask(),
|
|
183
|
+
"image-to-video": new Wavespeed.WavespeedAIImageToVideoTask(),
|
|
183
184
|
},
|
|
184
185
|
"zai-org": {
|
|
185
186
|
conversational: new Zai.ZaiConversationalTask(),
|
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.13.1";
|
|
6
6
|
exports.PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { TextToImageArgs } from "../tasks/cv/textToImage.js";
|
|
2
2
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
3
3
|
import type { TextToVideoArgs } from "../tasks/cv/textToVideo.js";
|
|
4
|
+
import type { ImageToVideoArgs } from "../tasks/cv/imageToVideo.js";
|
|
4
5
|
import type { BodyParams, RequestArgs, UrlParams } from "../types.js";
|
|
5
|
-
import type { TextToImageTaskHelper, TextToVideoTaskHelper, ImageToImageTaskHelper } from "./providerHelper.js";
|
|
6
|
+
import type { TextToImageTaskHelper, TextToVideoTaskHelper, ImageToImageTaskHelper, ImageToVideoTaskHelper } from "./providerHelper.js";
|
|
6
7
|
import { TaskProviderHelper } from "./providerHelper.js";
|
|
7
8
|
/**
|
|
8
9
|
* Response structure for initial task submission
|
|
@@ -24,7 +25,7 @@ interface WaveSpeedAISubmitTaskResponse {
|
|
|
24
25
|
declare abstract class WavespeedAITask extends TaskProviderHelper {
|
|
25
26
|
constructor(url?: string);
|
|
26
27
|
makeRoute(params: UrlParams): string;
|
|
27
|
-
preparePayload(params: BodyParams<ImageToImageArgs | TextToImageArgs | TextToVideoArgs>): Record<string, unknown>;
|
|
28
|
+
preparePayload(params: BodyParams<ImageToImageArgs | TextToImageArgs | TextToVideoArgs | ImageToVideoArgs>): Record<string, unknown>;
|
|
28
29
|
getResponse(response: WaveSpeedAISubmitTaskResponse, url?: string, headers?: Record<string, string>): Promise<Blob>;
|
|
29
30
|
}
|
|
30
31
|
export declare class WavespeedAITextToImageTask extends WavespeedAITask implements TextToImageTaskHelper {
|
|
@@ -37,5 +38,9 @@ export declare class WavespeedAIImageToImageTask extends WavespeedAITask impleme
|
|
|
37
38
|
constructor();
|
|
38
39
|
preparePayloadAsync(args: ImageToImageArgs): Promise<RequestArgs>;
|
|
39
40
|
}
|
|
41
|
+
export declare class WavespeedAIImageToVideoTask extends WavespeedAITask implements ImageToVideoTaskHelper {
|
|
42
|
+
constructor();
|
|
43
|
+
preparePayloadAsync(args: ImageToVideoArgs): Promise<RequestArgs>;
|
|
44
|
+
}
|
|
40
45
|
export {};
|
|
41
46
|
//# sourceMappingURL=wavespeed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wavespeed.d.ts","sourceRoot":"","sources":["../../../src/providers/wavespeed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SA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AM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CAkEhB;AAED,qBAAa,0BAA2B,SAAQ,eAAgB,YAAW,qBAAqB;;CAI/F;AAED,qBAAa,0BAA2B,SAAQ,eAAgB,YAAW,qBAAqB;;CAI/F;AAED,qBAAa,2BAA4B,SAAQ,eAAgB,YAAW,sBAAsB;;IAK3F,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CASvE;AAED,qBAAa,2BAA4B,SAAQ,eAAgB,YAAW,sBAAsB;;IAK3F,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CASvE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WavespeedAIImageToImageTask = exports.WavespeedAITextToVideoTask = exports.WavespeedAITextToImageTask = void 0;
|
|
3
|
+
exports.WavespeedAIImageToVideoTask = exports.WavespeedAIImageToImageTask = exports.WavespeedAITextToVideoTask = exports.WavespeedAITextToImageTask = void 0;
|
|
4
4
|
const delay_js_1 = require("../utils/delay.js");
|
|
5
5
|
const omit_js_1 = require("../utils/omit.js");
|
|
6
6
|
const base64FromBytes_js_1 = require("../utils/base64FromBytes.js");
|
|
@@ -32,10 +32,14 @@ class WavespeedAITask extends providerHelper_js_1.TaskProviderHelper {
|
|
|
32
32
|
return payload;
|
|
33
33
|
}
|
|
34
34
|
async getResponse(response, url, headers) {
|
|
35
|
-
if (!headers) {
|
|
35
|
+
if (!url || !headers) {
|
|
36
36
|
throw new errors_js_1.InferenceClientInputError("Headers are required for WaveSpeed AI API calls");
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const parsedUrl = new URL(url);
|
|
39
|
+
const resultPath = new URL(response.data.urls.get).pathname;
|
|
40
|
+
/// override the base url to use the router.huggingface.co if going through huggingface router
|
|
41
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/wavespeed" : ""}`;
|
|
42
|
+
const resultUrl = `${baseUrl}${resultPath}`;
|
|
39
43
|
// Poll for results until completion
|
|
40
44
|
while (true) {
|
|
41
45
|
const resultResponse = await fetch(resultUrl, { headers });
|
|
@@ -101,3 +105,16 @@ class WavespeedAIImageToImageTask extends WavespeedAITask {
|
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
exports.WavespeedAIImageToImageTask = WavespeedAIImageToImageTask;
|
|
108
|
+
class WavespeedAIImageToVideoTask extends WavespeedAITask {
|
|
109
|
+
constructor() {
|
|
110
|
+
super(WAVESPEEDAI_API_BASE_URL);
|
|
111
|
+
}
|
|
112
|
+
async preparePayloadAsync(args) {
|
|
113
|
+
return {
|
|
114
|
+
...args,
|
|
115
|
+
inputs: args.parameters?.prompt,
|
|
116
|
+
image: (0, base64FromBytes_js_1.base64FromBytes)(new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await args.inputs.arrayBuffer())),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.WavespeedAIImageToVideoTask = WavespeedAIImageToVideoTask;
|
|
@@ -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;AAuY5B,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"}
|
|
@@ -189,6 +189,8 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
|
189
189
|
: providerModelId ?? model.id,
|
|
190
190
|
billTo: opts?.billTo,
|
|
191
191
|
endpointUrl: opts?.endpointUrl,
|
|
192
|
+
task,
|
|
193
|
+
directRequest: !!opts?.directRequest,
|
|
192
194
|
};
|
|
193
195
|
/// Iterate over clients => check if a snippet exists => generate
|
|
194
196
|
const clients = provider === "auto" && task !== "conversational" ? CLIENTS_NON_CONVERSATIONAL_AUTO_POLICY : CLIENTS;
|
|
@@ -20,8 +20,8 @@ exports.templates = {
|
|
|
20
20
|
"basic": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tmodel: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
21
21
|
"basicAudio": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
22
22
|
"basicImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
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);",
|
|
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
|
|
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{% if directRequest %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{% else %}\n model: \"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
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 model: \"{{ providerModelId }}\",\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}",
|
|
25
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
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",
|
|
27
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)",
|
|
@@ -43,12 +43,12 @@ exports.templates = {
|
|
|
43
43
|
"basic": "result = client.{{ methodName }}(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n)",
|
|
44
44
|
"basicAudio": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
45
45
|
"basicImage": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
46
|
-
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
47
|
-
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{
|
|
46
|
+
"conversational": "completion = client.chat.completions.create(\n{% if directRequest %}\n model=\"{{ model.id }}\",\n{% else %}\n model=\"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
47
|
+
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ providerModelId }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
48
48
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
49
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
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",
|
|
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)",
|
|
51
|
+
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n{% if task != \"conversational\" or directRequest %}\n provider=\"{{ provider }}\",\n{% endif %}\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
52
52
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
53
53
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
54
54
|
"textToImage": "# output is a PIL.Image object\nimage = client.text_to_image(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatCompletionStream.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/chatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAG1F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"chatCompletionStream.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/chatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAG1F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKxD;;GAEG;AACH,wBAAuB,oBAAoB,CAC1C,IAAI,EAAE,QAAQ,GAAG,mBAAmB,EACpC,OAAO,CAAC,EAAE,OAAO,GACf,cAAc,CAAC,0BAA0B,CAAC,CAa5C"}
|
|
@@ -4,12 +4,20 @@ exports.chatCompletionStream = chatCompletionStream;
|
|
|
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 providerHelper_js_1 = require("../../providers/providerHelper.js");
|
|
7
8
|
/**
|
|
8
9
|
* Use to continue text from a prompt. Same as `textGeneration` but returns generator that can be read one token at a time
|
|
9
10
|
*/
|
|
10
11
|
async function* chatCompletionStream(args, options) {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
let providerHelper;
|
|
13
|
+
if (!args.provider || args.provider === "auto") {
|
|
14
|
+
// Special case: we have a dedicated auto-router for conversational models. No need to fetch provider mapping.
|
|
15
|
+
providerHelper = new providerHelper_js_1.AutoRouterConversationalTask();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const provider = await (0, getInferenceProviderMapping_js_1.resolveProvider)(args.provider, args.model, args.endpointUrl);
|
|
19
|
+
providerHelper = (0, getProviderHelper_js_1.getProviderHelper)(provider, "conversational");
|
|
20
|
+
}
|
|
13
21
|
yield* (0, request_js_1.innerStreamingRequest)(args, providerHelper, {
|
|
14
22
|
...options,
|
|
15
23
|
task: "conversational",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProviderHelper.d.ts","sourceRoot":"","sources":["../../../src/lib/getProviderHelper.ts"],"names":[],"mappings":"AAiBA,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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gC,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"}
|
|
@@ -143,6 +143,7 @@ export const PROVIDERS = {
|
|
|
143
143
|
"text-to-image": new Wavespeed.WavespeedAITextToImageTask(),
|
|
144
144
|
"text-to-video": new Wavespeed.WavespeedAITextToVideoTask(),
|
|
145
145
|
"image-to-image": new Wavespeed.WavespeedAIImageToImageTask(),
|
|
146
|
+
"image-to-video": new Wavespeed.WavespeedAIImageToVideoTask(),
|
|
146
147
|
},
|
|
147
148
|
"zai-org": {
|
|
148
149
|
conversational: new Zai.ZaiConversationalTask(),
|
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.13.1";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { TextToImageArgs } from "../tasks/cv/textToImage.js";
|
|
2
2
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
3
3
|
import type { TextToVideoArgs } from "../tasks/cv/textToVideo.js";
|
|
4
|
+
import type { ImageToVideoArgs } from "../tasks/cv/imageToVideo.js";
|
|
4
5
|
import type { BodyParams, RequestArgs, UrlParams } from "../types.js";
|
|
5
|
-
import type { TextToImageTaskHelper, TextToVideoTaskHelper, ImageToImageTaskHelper } from "./providerHelper.js";
|
|
6
|
+
import type { TextToImageTaskHelper, TextToVideoTaskHelper, ImageToImageTaskHelper, ImageToVideoTaskHelper } from "./providerHelper.js";
|
|
6
7
|
import { TaskProviderHelper } from "./providerHelper.js";
|
|
7
8
|
/**
|
|
8
9
|
* Response structure for initial task submission
|
|
@@ -24,7 +25,7 @@ interface WaveSpeedAISubmitTaskResponse {
|
|
|
24
25
|
declare abstract class WavespeedAITask extends TaskProviderHelper {
|
|
25
26
|
constructor(url?: string);
|
|
26
27
|
makeRoute(params: UrlParams): string;
|
|
27
|
-
preparePayload(params: BodyParams<ImageToImageArgs | TextToImageArgs | TextToVideoArgs>): Record<string, unknown>;
|
|
28
|
+
preparePayload(params: BodyParams<ImageToImageArgs | TextToImageArgs | TextToVideoArgs | ImageToVideoArgs>): Record<string, unknown>;
|
|
28
29
|
getResponse(response: WaveSpeedAISubmitTaskResponse, url?: string, headers?: Record<string, string>): Promise<Blob>;
|
|
29
30
|
}
|
|
30
31
|
export declare class WavespeedAITextToImageTask extends WavespeedAITask implements TextToImageTaskHelper {
|
|
@@ -37,5 +38,9 @@ export declare class WavespeedAIImageToImageTask extends WavespeedAITask impleme
|
|
|
37
38
|
constructor();
|
|
38
39
|
preparePayloadAsync(args: ImageToImageArgs): Promise<RequestArgs>;
|
|
39
40
|
}
|
|
41
|
+
export declare class WavespeedAIImageToVideoTask extends WavespeedAITask implements ImageToVideoTaskHelper {
|
|
42
|
+
constructor();
|
|
43
|
+
preparePayloadAsync(args: ImageToVideoArgs): Promise<RequestArgs>;
|
|
44
|
+
}
|
|
40
45
|
export {};
|
|
41
46
|
//# sourceMappingURL=wavespeed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wavespeed.d.ts","sourceRoot":"","sources":["../../../src/providers/wavespeed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAItE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"wavespeed.d.ts","sourceRoot":"","sources":["../../../src/providers/wavespeed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAItE,OAAO,KAAK,EACX,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA6BzD;;GAEG;AACH,UAAU,yBAAyB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE;QACL,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC;CACF;AAWD;;GAEG;AACH,UAAU,6BAA6B;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,yBAAyB,CAAC;CAChC;AAED,uBAAe,eAAgB,SAAQ,kBAAkB;gBAC5C,GAAG,CAAC,EAAE,MAAM;IAIxB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAIpC,cAAc,CACb,MAAM,EAAE,UAAU,CAAC,gBAAgB,GAAG,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAAC,GACzF,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkBX,WAAW,CACzB,QAAQ,EAAE,6BAA6B,EACvC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CAkEhB;AAED,qBAAa,0BAA2B,SAAQ,eAAgB,YAAW,qBAAqB;;CAI/F;AAED,qBAAa,0BAA2B,SAAQ,eAAgB,YAAW,qBAAqB;;CAI/F;AAED,qBAAa,2BAA4B,SAAQ,eAAgB,YAAW,sBAAsB;;IAK3F,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CASvE;AAED,qBAAa,2BAA4B,SAAQ,eAAgB,YAAW,sBAAsB;;IAK3F,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;CASvE"}
|
|
@@ -29,10 +29,14 @@ class WavespeedAITask extends TaskProviderHelper {
|
|
|
29
29
|
return payload;
|
|
30
30
|
}
|
|
31
31
|
async getResponse(response, url, headers) {
|
|
32
|
-
if (!headers) {
|
|
32
|
+
if (!url || !headers) {
|
|
33
33
|
throw new InferenceClientInputError("Headers are required for WaveSpeed AI API calls");
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const parsedUrl = new URL(url);
|
|
36
|
+
const resultPath = new URL(response.data.urls.get).pathname;
|
|
37
|
+
/// override the base url to use the router.huggingface.co if going through huggingface router
|
|
38
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/wavespeed" : ""}`;
|
|
39
|
+
const resultUrl = `${baseUrl}${resultPath}`;
|
|
36
40
|
// Poll for results until completion
|
|
37
41
|
while (true) {
|
|
38
42
|
const resultResponse = await fetch(resultUrl, { headers });
|
|
@@ -95,3 +99,15 @@ export class WavespeedAIImageToImageTask extends WavespeedAITask {
|
|
|
95
99
|
};
|
|
96
100
|
}
|
|
97
101
|
}
|
|
102
|
+
export class WavespeedAIImageToVideoTask extends WavespeedAITask {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(WAVESPEEDAI_API_BASE_URL);
|
|
105
|
+
}
|
|
106
|
+
async preparePayloadAsync(args) {
|
|
107
|
+
return {
|
|
108
|
+
...args,
|
|
109
|
+
inputs: args.parameters?.prompt,
|
|
110
|
+
image: base64FromBytes(new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await args.inputs.arrayBuffer())),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -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;AAuY5B,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"}
|
|
@@ -186,6 +186,8 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
|
|
|
186
186
|
: providerModelId ?? model.id,
|
|
187
187
|
billTo: opts?.billTo,
|
|
188
188
|
endpointUrl: opts?.endpointUrl,
|
|
189
|
+
task,
|
|
190
|
+
directRequest: !!opts?.directRequest,
|
|
189
191
|
};
|
|
190
192
|
/// Iterate over clients => check if a snippet exists => generate
|
|
191
193
|
const clients = provider === "auto" && task !== "conversational" ? CLIENTS_NON_CONVERSATIONAL_AUTO_POLICY : CLIENTS;
|
|
@@ -17,8 +17,8 @@ export const templates = {
|
|
|
17
17
|
"basic": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tmodel: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
18
18
|
"basicAudio": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
19
19
|
"basicImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
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);",
|
|
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
|
|
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{% if directRequest %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{% else %}\n model: \"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
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 model: \"{{ providerModelId }}\",\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}",
|
|
22
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
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",
|
|
24
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)",
|
|
@@ -40,12 +40,12 @@ export const templates = {
|
|
|
40
40
|
"basic": "result = client.{{ methodName }}(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n)",
|
|
41
41
|
"basicAudio": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
42
42
|
"basicImage": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
43
|
-
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
44
|
-
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{
|
|
43
|
+
"conversational": "completion = client.chat.completions.create(\n{% if directRequest %}\n model=\"{{ model.id }}\",\n{% else %}\n model=\"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
44
|
+
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ providerModelId }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
45
45
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
46
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
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",
|
|
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)",
|
|
48
|
+
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n{% if task != \"conversational\" or directRequest %}\n provider=\"{{ provider }}\",\n{% endif %}\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
49
49
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
50
50
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
51
51
|
"textToImage": "# output is a PIL.Image object\nimage = client.text_to_image(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatCompletionStream.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/chatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAG1F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"chatCompletionStream.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/chatCompletionStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAG1F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKxD;;GAEG;AACH,wBAAuB,oBAAoB,CAC1C,IAAI,EAAE,QAAQ,GAAG,mBAAmB,EACpC,OAAO,CAAC,EAAE,OAAO,GACf,cAAc,CAAC,0BAA0B,CAAC,CAa5C"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
|
|
2
2
|
import { getProviderHelper } from "../../lib/getProviderHelper.js";
|
|
3
3
|
import { innerStreamingRequest } from "../../utils/request.js";
|
|
4
|
+
import { AutoRouterConversationalTask } from "../../providers/providerHelper.js";
|
|
4
5
|
/**
|
|
5
6
|
* Use to continue text from a prompt. Same as `textGeneration` but returns generator that can be read one token at a time
|
|
6
7
|
*/
|
|
7
8
|
export async function* chatCompletionStream(args, options) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let providerHelper;
|
|
10
|
+
if (!args.provider || args.provider === "auto") {
|
|
11
|
+
// Special case: we have a dedicated auto-router for conversational models. No need to fetch provider mapping.
|
|
12
|
+
providerHelper = new AutoRouterConversationalTask();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
16
|
+
providerHelper = getProviderHelper(provider, "conversational");
|
|
17
|
+
}
|
|
10
18
|
yield* innerStreamingRequest(args, providerHelper, {
|
|
11
19
|
...options,
|
|
12
20
|
task: "conversational",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huggingface/inference",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.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.62",
|
|
44
44
|
"@huggingface/jinja": "^0.5.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -178,6 +178,7 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
|
|
|
178
178
|
"text-to-image": new Wavespeed.WavespeedAITextToImageTask(),
|
|
179
179
|
"text-to-video": new Wavespeed.WavespeedAITextToVideoTask(),
|
|
180
180
|
"image-to-image": new Wavespeed.WavespeedAIImageToImageTask(),
|
|
181
|
+
"image-to-video": new Wavespeed.WavespeedAIImageToVideoTask(),
|
|
181
182
|
},
|
|
182
183
|
"zai-org": {
|
|
183
184
|
conversational: new Zai.ZaiConversationalTask(),
|
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.13.1";
|
|
3
3
|
export const PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { TextToImageArgs } from "../tasks/cv/textToImage.js";
|
|
2
2
|
import type { ImageToImageArgs } from "../tasks/cv/imageToImage.js";
|
|
3
3
|
import type { TextToVideoArgs } from "../tasks/cv/textToVideo.js";
|
|
4
|
+
import type { ImageToVideoArgs } from "../tasks/cv/imageToVideo.js";
|
|
4
5
|
import type { BodyParams, RequestArgs, UrlParams } from "../types.js";
|
|
5
6
|
import { delay } from "../utils/delay.js";
|
|
6
7
|
import { omit } from "../utils/omit.js";
|
|
7
8
|
import { base64FromBytes } from "../utils/base64FromBytes.js";
|
|
8
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
TextToImageTaskHelper,
|
|
11
|
+
TextToVideoTaskHelper,
|
|
12
|
+
ImageToImageTaskHelper,
|
|
13
|
+
ImageToVideoTaskHelper,
|
|
14
|
+
} from "./providerHelper.js";
|
|
9
15
|
import { TaskProviderHelper } from "./providerHelper.js";
|
|
10
16
|
import {
|
|
11
17
|
InferenceClientInputError,
|
|
@@ -72,7 +78,9 @@ abstract class WavespeedAITask extends TaskProviderHelper {
|
|
|
72
78
|
return `/api/v3/${params.model}`;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
preparePayload(
|
|
81
|
+
preparePayload(
|
|
82
|
+
params: BodyParams<ImageToImageArgs | TextToImageArgs | TextToVideoArgs | ImageToVideoArgs>
|
|
83
|
+
): Record<string, unknown> {
|
|
76
84
|
const payload: Record<string, unknown> = {
|
|
77
85
|
...omit(params.args, ["inputs", "parameters"]),
|
|
78
86
|
...params.args.parameters,
|
|
@@ -95,11 +103,17 @@ abstract class WavespeedAITask extends TaskProviderHelper {
|
|
|
95
103
|
url?: string,
|
|
96
104
|
headers?: Record<string, string>
|
|
97
105
|
): Promise<Blob> {
|
|
98
|
-
if (!headers) {
|
|
106
|
+
if (!url || !headers) {
|
|
99
107
|
throw new InferenceClientInputError("Headers are required for WaveSpeed AI API calls");
|
|
100
108
|
}
|
|
101
109
|
|
|
102
|
-
const
|
|
110
|
+
const parsedUrl = new URL(url);
|
|
111
|
+
const resultPath = new URL(response.data.urls.get).pathname;
|
|
112
|
+
/// override the base url to use the router.huggingface.co if going through huggingface router
|
|
113
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${
|
|
114
|
+
parsedUrl.host === "router.huggingface.co" ? "/wavespeed" : ""
|
|
115
|
+
}`;
|
|
116
|
+
const resultUrl = `${baseUrl}${resultPath}`;
|
|
103
117
|
|
|
104
118
|
// Poll for results until completion
|
|
105
119
|
while (true) {
|
|
@@ -183,3 +197,19 @@ export class WavespeedAIImageToImageTask extends WavespeedAITask implements Imag
|
|
|
183
197
|
};
|
|
184
198
|
}
|
|
185
199
|
}
|
|
200
|
+
|
|
201
|
+
export class WavespeedAIImageToVideoTask extends WavespeedAITask implements ImageToVideoTaskHelper {
|
|
202
|
+
constructor() {
|
|
203
|
+
super(WAVESPEEDAI_API_BASE_URL);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async preparePayloadAsync(args: ImageToVideoArgs): Promise<RequestArgs> {
|
|
207
|
+
return {
|
|
208
|
+
...args,
|
|
209
|
+
inputs: args.parameters?.prompt,
|
|
210
|
+
image: base64FromBytes(
|
|
211
|
+
new Uint8Array(args.inputs instanceof ArrayBuffer ? args.inputs : await (args.inputs as Blob).arrayBuffer())
|
|
212
|
+
),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -60,6 +60,8 @@ interface TemplateParams {
|
|
|
60
60
|
importBase64?: boolean; // specific to snippetImportRequests
|
|
61
61
|
importJson?: boolean; // specific to snippetImportRequests
|
|
62
62
|
endpointUrl?: string;
|
|
63
|
+
task?: InferenceTask;
|
|
64
|
+
directRequest?: boolean;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
// Helpers to find + load templates
|
|
@@ -263,6 +265,8 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
|
|
|
263
265
|
: providerModelId ?? model.id,
|
|
264
266
|
billTo: opts?.billTo,
|
|
265
267
|
endpointUrl: opts?.endpointUrl,
|
|
268
|
+
task,
|
|
269
|
+
directRequest: !!opts?.directRequest,
|
|
266
270
|
};
|
|
267
271
|
|
|
268
272
|
/// Iterate over clients => check if a snippet exists => generate
|
|
@@ -17,8 +17,8 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
17
17
|
"basic": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tmodel: \"{{ model.id }}\",\n\tinputs: {{ inputs.asObj.inputs }},\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
18
18
|
"basicAudio": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
19
19
|
"basicImage": "import { InferenceClient } from \"@huggingface/inference\";\n\nconst client = new InferenceClient(\"{{ accessToken }}\");\n\nconst data = fs.readFileSync({{inputs.asObj.inputs}});\n\nconst output = await client.{{ methodName }}({\n{% if endpointUrl %}\n endpointUrl: \"{{ endpointUrl }}\",\n{% endif %}\n\tdata,\n\tmodel: \"{{ model.id }}\",\n\tprovider: \"{{ provider }}\",\n}{% if billTo %}, {\n\tbillTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(output);",
|
|
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);",
|
|
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
|
|
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{% if directRequest %}\n provider: \"{{ provider }}\",\n model: \"{{ model.id }}\",\n{% else %}\n model: \"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asTsString }}\n}{% if billTo %}, {\n billTo: \"{{ billTo }}\",\n}{% endif %});\n\nconsole.log(chatCompletion.choices[0].message);",
|
|
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 model: \"{{ providerModelId }}\",\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}",
|
|
22
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
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",
|
|
24
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)",
|
|
@@ -40,12 +40,12 @@ export const templates: Record<string, Record<string, Record<string, string>>> =
|
|
|
40
40
|
"basic": "result = client.{{ methodName }}(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n)",
|
|
41
41
|
"basicAudio": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
42
42
|
"basicImage": "output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model=\"{{ model.id }}\")",
|
|
43
|
-
"conversational": "completion = client.chat.completions.create(\n model=\"{{ model.id }}\",\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
44
|
-
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{
|
|
43
|
+
"conversational": "completion = client.chat.completions.create(\n{% if directRequest %}\n model=\"{{ model.id }}\",\n{% else %}\n model=\"{{ providerModelId }}\",\n{% endif %}\n{{ inputs.asPythonString }}\n)\n\nprint(completion.choices[0].message) ",
|
|
44
|
+
"conversationalStream": "stream = client.chat.completions.create(\n model=\"{{ providerModelId }}\",\n{{ inputs.asPythonString }}\n stream=True,\n)\n\nfor chunk in stream:\n print(chunk.choices[0].delta.content, end=\"\") ",
|
|
45
45
|
"documentQuestionAnswering": "output = client.document_question_answering(\n \"{{ inputs.asObj.image }}\",\n question=\"{{ inputs.asObj.question }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
46
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
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",
|
|
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)",
|
|
48
|
+
"importInferenceClient": "from huggingface_hub import InferenceClient\n\nclient = InferenceClient(\n{% if endpointUrl %}\n base_url=\"{{ baseUrl }}\",\n{% endif %}\n{% if task != \"conversational\" or directRequest %}\n provider=\"{{ provider }}\",\n{% endif %}\n api_key=\"{{ accessToken }}\",\n{% if billTo %}\n bill_to=\"{{ billTo }}\",\n{% endif %}\n)",
|
|
49
49
|
"questionAnswering": "answer = client.question_answering(\n question=\"{{ inputs.asObj.question }}\",\n context=\"{{ inputs.asObj.context }}\",\n model=\"{{ model.id }}\",\n) ",
|
|
50
50
|
"tableQuestionAnswering": "answer = client.table_question_answering(\n query=\"{{ inputs.asObj.query }}\",\n table={{ inputs.asObj.table }},\n model=\"{{ model.id }}\",\n) ",
|
|
51
51
|
"textToImage": "# output is a PIL.Image object\nimage = client.text_to_image(\n {{ inputs.asObj.inputs }},\n model=\"{{ model.id }}\",\n) ",
|
|
@@ -3,6 +3,8 @@ import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
|
|
|
3
3
|
import { getProviderHelper } from "../../lib/getProviderHelper.js";
|
|
4
4
|
import type { BaseArgs, Options } from "../../types.js";
|
|
5
5
|
import { innerStreamingRequest } from "../../utils/request.js";
|
|
6
|
+
import type { ConversationalTaskHelper, TaskProviderHelper } from "../../providers/providerHelper.js";
|
|
7
|
+
import { AutoRouterConversationalTask } from "../../providers/providerHelper.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Use to continue text from a prompt. Same as `textGeneration` but returns generator that can be read one token at a time
|
|
@@ -11,8 +13,14 @@ export async function* chatCompletionStream(
|
|
|
11
13
|
args: BaseArgs & ChatCompletionInput,
|
|
12
14
|
options?: Options
|
|
13
15
|
): AsyncGenerator<ChatCompletionStreamOutput> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
let providerHelper: ConversationalTaskHelper & TaskProviderHelper;
|
|
17
|
+
if (!args.provider || args.provider === "auto") {
|
|
18
|
+
// Special case: we have a dedicated auto-router for conversational models. No need to fetch provider mapping.
|
|
19
|
+
providerHelper = new AutoRouterConversationalTask();
|
|
20
|
+
} else {
|
|
21
|
+
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
22
|
+
providerHelper = getProviderHelper(provider, "conversational");
|
|
23
|
+
}
|
|
16
24
|
yield* innerStreamingRequest<ChatCompletionStreamOutput>(args, providerHelper, {
|
|
17
25
|
...options,
|
|
18
26
|
task: "conversational",
|