Implement Gemini LLM module for document generation (first non tested prototype)

This commit is contained in:
MikeHughes-BIN
2025-11-17 21:16:50 +01:00
parent 4b72568ad3
commit 8e7e0b5043
+55
View File
@@ -0,0 +1,55 @@
import fs from "fs";
import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const { GoogleGenAI } = require("@google/genai");
const ai = new GoogleGenAI({
apiKey: process.env.GOOGLE_API_KEY
});
const outputDir = `${__dirname}/../../../storage/documents`;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
module.exports = {
name: "llm-gemini",
type: "llm",
displayname: "Gemini LLM",
async function(parameter) {
try {
console.log("Gemini LLM module invoked with parameters:", parameter);
await this.createDocumentFromTranscript(
parameter.inputTranscriptPath,
parameter.documentType
);
} catch (error) {
console.error("Error in Gemini LLM module:", error);
}
},
createDocumentFromTranscript: async function(transcriptPath, documentType) {
try {
const transcript = await fs.promises.readFile(transcriptPath, "utf-8");
const text = `${documentType}\n\n${transcript}`;
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: text
});
const output = response.text ?? "";
fs.writeFileSync(`${outputDir}/test.md`, output, "utf8");
console.log("Generated document written to test.md");
} catch (error) {
console.error("Error generating content:", error);
}
}
};