mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
Implement Gemini LLM module for document generation (first non tested prototype)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user