feat: no more imagegen
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 48s

This commit is contained in:
2026-01-08 17:38:24 -08:00
parent 23624ce05f
commit aa970fabc1
+3 -39
View File
@@ -5,30 +5,22 @@
*/ */
import { Anthropic } from "@anthropic-ai/sdk"; import { Anthropic } from "@anthropic-ai/sdk";
import { import type { MessageCreateOptions } from "discord.js";
GoogleGenAI,
} from "@google/genai";
import { AttachmentBuilder, type MessageCreateOptions } from "discord.js";
/** /**
* Utility class for generating project information and images. * Utility class for generating project information and images.
*/ */
export class Ai { export class Ai {
private readonly anthropic: Anthropic; private readonly anthropic: Anthropic;
private readonly gemini: GoogleGenAI;
/** /**
* Creates a new instance of the Ai class. * Creates a new instance of the Ai class.
* @param anthropicKey - The API key for the Anthropic API. * @param anthropicKey - The API key for the Anthropic API.
* @param geminiKey - The API key for the Gemini API.
*/ */
public constructor(anthropicKey: string, geminiKey: string) { public constructor(anthropicKey: string) {
this.anthropic = new Anthropic({ this.anthropic = new Anthropic({
apiKey: anthropicKey, apiKey: anthropicKey,
}); });
this.gemini = new GoogleGenAI({
apiKey: geminiKey,
});
} }
/** /**
@@ -49,19 +41,11 @@ export class Ai {
`Your task is to generate a project name based on the user's description. Provide ONLY a list of 1-5 fitting names, and an explanation for why you chose them. Note that project names should be unique. Here's a list of all existing project names: ${projectResponse. `Your task is to generate a project name based on the user's description. Provide ONLY a list of 1-5 fitting names, and an explanation for why you chose them. Note that project names should be unique. Here's a list of all existing project names: ${projectResponse.
map((p) => { map((p) => {
return p.name; return p.name;
}). }).join(", ")}`,
join(", ")}`,
prompt, prompt,
); );
const image = await this.generateImage(prompt);
if (image === null) {
return {
content: `Project Name: ${names}\nProject Description: ${prompt}\nSorry, I was unable to generate an image for you.`,
};
}
return { return {
content: `Project Name: ${names}\nProject Description: ${prompt}`, content: `Project Name: ${names}\nProject Description: ${prompt}`,
files: [ new AttachmentBuilder(image, { name: "avatar.png" }) ],
}; };
} }
@@ -88,24 +72,4 @@ export class Ai {
join(""); join("");
return text; return text;
} }
private async generateImage(prompt: string): Promise<Buffer | null> {
const response = await this.gemini.models.generateContent({
config: {
imageConfig: { aspectRatio: "3:4" },
systemInstruction:
`Your task is to generate a full body anime girl mascot for this project. This means the full character should be visible. The image should have a white background. NEVER include text in the image, no text anywhere at all. The project description is provided by the user.`,
},
contents: prompt,
model: "gemini-2.5-flash-image",
});
const image = response.candidates?.[0]?.content?.parts?.find((p) => {
return Boolean(p.inlineData);
});
const base64 = image?.inlineData?.data;
if (base64 === undefined) {
return null;
}
return Buffer.from(base64, "base64");
}
} }