Skip to content

Commit

Permalink
parity imagine with flux 1
Browse files Browse the repository at this point in the history
  • Loading branch information
daniwasonline committed Nov 14, 2024
1 parent 5e05543 commit 4381f5a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/commands/imagine.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default {
name: "stabilityai/stable-diffusion-xl-base-1.0",
value: "@cf/stabilityai/stable-diffusion-xl-base-1.0",
},
{
name: "black-forest-labs/flux-1-schnell",
value: "@cf/black-forest-labs/flux-1-schnell",
},
])
.setRequired(true),
)
Expand Down Expand Up @@ -66,7 +70,41 @@ export default {
content: `The model did not generate an image.`,
});

const buffer = Buffer.from(callToModel);
let buffer = null;

try {
const textDecoder = new TextDecoder();
const text = textDecoder.decode(callToModel);
const jsonResponse = JSON.parse(text);

if (jsonResponse?.success === false) {
if (jsonResponse?.errors?.find((e) => e?.code === 3030)) {
return await interaction.editReply({
content: `❌ The model rejected your prompt because it contained a disallowed token (NSFW content). Please try again with a different prompt.`,
});
} else {
return await interaction.editReply({
content: `The model could not generate an image. Attached is a log of the error.`,
files: [
{
attachment: Buffer.from(callToModel, "utf-8"),
name: "error.txt",
},
],
});
}
}

if (jsonResponse?.result?.image) {
buffer = Buffer.from(jsonResponse.result.image, "base64");
} else {
buffer = Buffer.from(callToModel);
}
} catch (e) {
buffer = Buffer.from(callToModel);
}

if (buffer === null) buffer = Buffer.from(callToModel);

await interaction.editReply({
content: `\`${prompt}\`\n*generated with \`${model}\`*`,
Expand Down

0 comments on commit 4381f5a

Please sign in to comment.