Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inference/fal-ai): b64 response format argument #1149

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/inference/src/tasks/cv/textToImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ interface OutputUrlImageGeneration {
output: string[];
}

async function getResponseFormatArg(provider: string) {
if (provider == "replicate") {
return undefined;
} else if (provider === "fal-ai") {
return { sync_mode: true };
}
return { response_format: "base64" };
}

/**
* This task reads some text input and outputs an image.
* Recommended model: stabilityai/stable-diffusion-2
Expand All @@ -25,14 +34,15 @@ export async function textToImage(args: TextToImageArgs, options?: Options): Pro
? {
...omit(args, ["inputs", "parameters"]),
...args.parameters,
...(args.provider !== "replicate" ? { response_format: "base64" } : undefined),
...(await getResponseFormatArg(args.provider)),
prompt: args.inputs,
}
: args;
const res = await request<TextToImageOutput | Base64ImageGeneration | OutputUrlImageGeneration>(payload, {
...options,
taskHint: "text-to-image",
});

if (res && typeof res === "object") {
if (args.provider === "fal-ai" && "images" in res && Array.isArray(res.images) && res.images[0].url) {
const image = await fetch(res.images[0].url);
Expand Down
387 changes: 387 additions & 0 deletions packages/inference/test/tapes.json

Large diffs are not rendered by default.