Skip to content

Commit 95d33d8

Browse files
committed
fix texttoImage
1 parent cb1ff63 commit 95d33d8

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ function makeUrl(params: {
240240
const baseUrl = shouldProxy
241241
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
242242
: HYPERBOLIC_API_BASE_URL;
243+
244+
if (params.taskHint === "text-generation") {
245+
return `${baseUrl}/v1/chat/completions`;
246+
}
247+
if (params.taskHint === "text-to-image") {
248+
return `${baseUrl}/v1/images/generations`;
249+
}
243250
return `${baseUrl}/v1/chat/completions`;
244251
}
245252
default: {

packages/inference/src/tasks/cv/textToImage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export async function textToImage(args: TextToImageArgs, options?: Options): Pro
2424
args.provider === "together" ||
2525
args.provider === "fal-ai" ||
2626
args.provider === "replicate" ||
27-
args.provider === "nebius"
27+
args.provider === "nebius" ||
28+
args.provider === "hyperbolic"
2829
? {
2930
...omit(args, ["inputs", "parameters"]),
3031
...args.parameters,
@@ -42,6 +43,11 @@ export async function textToImage(args: TextToImageArgs, options?: Options): Pro
4243
const image = await fetch(res.images[0].url);
4344
return await image.blob();
4445
}
46+
if (args.provider === "hyperbolic" && "images" in res && Array.isArray(res.images) && res.images[0].image) {
47+
const base64Response = await fetch(`data:image/jpeg;base64,${res.images[0].image}`);
48+
const blob = await base64Response.blob();
49+
return blob;
50+
}
4551
if ("data" in res && Array.isArray(res.data) && res.data[0].b64_json) {
4652
const base64Data = res.data[0].b64_json;
4753
const base64Response = await fetch(`data:image/jpeg;base64,${base64Data}`);

packages/inference/test/HfInference.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, describe, expect, it } from "vitest";
22

33
import type { ChatCompletionStreamOutput } from "@huggingface/tasks";
44

5+
import type { TextToImageArgs } from "../src";
56
import { chatCompletion, HfInference } from "../src";
67
import { textToVideo } from "../src/tasks/cv/textToVideo";
78
import { readTestFile } from "./test-files";
@@ -1227,8 +1228,13 @@ describe.concurrent("HfInference", () => {
12271228
const res = await client.textToImage({
12281229
model: "stabilityai/stable-diffusion-2",
12291230
provider: "hyperbolic",
1230-
messages: [{ role: "user", content: "award winning high resolution photo of a giant tortoise" }],
1231-
});
1231+
inputs: "award winning high resolution photo of a giant tortoise",
1232+
parameters: {
1233+
model_name: "SD2",
1234+
height: 1024,
1235+
width: 1024,
1236+
},
1237+
} satisfies TextToImageArgs);
12321238
expect(res).toBeInstanceOf(Blob);
12331239
});
12341240

0 commit comments

Comments
 (0)