Skip to content

Commit f1edf12

Browse files
zekehanouticelina
andauthored
fix(inference): support string URL output in Replicate text-to-image (#1835)
This PR adds support for Replicate text-to-image models that return a single URL string instead of an array of URLs. This should fix replicate/huggingface-model-mappings#31, which is currently failing: <img width="1048" height="432" alt="image" src="https://github.com/user-attachments/assets/a9750364-7b8d-4f2f-96e9-4a1afb39af40" /> ## Solution The `ReplicateTextToImageTask.getResponse` method previously only handled array outputs, causing errors for models that return a single string URL. This change makes the text-to-image implementation consistent with other tasks like `ReplicateImageToImageTask` and `ReplicateTextToVideoTask`, which already support both formats. ## Prompts > Does the replicate text-to-image implementation in this codebase support models that return a URL as output? Or does it always expect an array of image URLs? > Let's update it to allow URL strings as a valid output response > commit the changes to a branch, push it, and open a PR against the upstream repo: huggingface/huggingface.js --------- Co-authored-by: Celina Hanouti <hanouticelina@gmail.com>
1 parent 32f0da0 commit f1edf12

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/inference/src/providers/replicate.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ export class ReplicateTextToImageTask extends ReplicateTask implements TextToIma
9595
): Promise<string | Blob | Record<string, unknown>> {
9696
void url;
9797
void headers;
98+
99+
// Handle string output
100+
if (typeof res === "object" && "output" in res && typeof res.output === "string" && isUrl(res.output)) {
101+
if (outputType === "json") {
102+
return { ...res };
103+
}
104+
if (outputType === "url") {
105+
return res.output;
106+
}
107+
const urlResponse = await fetch(res.output);
108+
return await urlResponse.blob();
109+
}
110+
111+
// Handle array output
98112
if (
99113
typeof res === "object" &&
100114
"output" in res &&

0 commit comments

Comments
 (0)