Skip to content

Commit 0b602a5

Browse files
authored
[Inference] Black Forest: poll for result even if output is url (huggingface#1209)
1 parent 081a6ab commit 0b602a5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ export async function textToImage(args: TextToImageArgs, options?: TextToImageOp
7878

7979
if (res && typeof res === "object") {
8080
if (args.provider === "black-forest-labs" && "polling_url" in res && typeof res.polling_url === "string") {
81-
if (options?.outputType === "url") {
82-
return res.polling_url;
83-
}
84-
return await pollBflResponse(res.polling_url);
81+
return await pollBflResponse(res.polling_url, options?.outputType);
8582
}
8683
if (args.provider === "fal-ai" && "images" in res && Array.isArray(res.images) && res.images[0].url) {
8784
if (options?.outputType === "url") {
@@ -132,7 +129,7 @@ export async function textToImage(args: TextToImageArgs, options?: TextToImageOp
132129
return res;
133130
}
134131

135-
async function pollBflResponse(url: string): Promise<Blob> {
132+
async function pollBflResponse(url: string, outputType?: "url" | "blob"): Promise<Blob> {
136133
const urlObj = new URL(url);
137134
for (let step = 0; step < 5; step++) {
138135
await delay(1000);
@@ -155,6 +152,9 @@ async function pollBflResponse(url: string): Promise<Blob> {
155152
"sample" in payload.result &&
156153
typeof payload.result.sample === "string"
157154
) {
155+
if (outputType === "url") {
156+
return payload.result.sample;
157+
}
158158
const image = await fetch(payload.result.sample);
159159
return await image.blob();
160160
}

0 commit comments

Comments
 (0)