mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const { GoogleGenAI } = require("@google/genai");
|
|
|
|
const outputDir = path.join(__dirname, "../../../storage/documents");
|
|
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
const ai = new GoogleGenAI({
|
|
apiKey: process.env.GOOGLE_API_KEY
|
|
});
|
|
|
|
module.exports = {
|
|
name: "llm-gemini",
|
|
type: "llm",
|
|
displayname: "Gemini LLM",
|
|
description: "Generates documents using Google Gemini LLM",
|
|
|
|
async function(parameter) {
|
|
try {
|
|
console.log("Gemini LLM module invoked with parameters:", parameter);
|
|
|
|
await this.createDocumentFromTranscript(
|
|
parameter.inputTranscriptPath,
|
|
parameter.documentTypePath,
|
|
parameter.language
|
|
);
|
|
|
|
} catch (error) {
|
|
console.error("Error in Gemini LLM module:", error);
|
|
}
|
|
},
|
|
|
|
createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") {
|
|
try {
|
|
const transcript = await fs.promises.readFile(transcriptPath, "utf-8");
|
|
const documentType = await fs.promises.readFile(documentTypePath, "utf-8");
|
|
|
|
const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`;
|
|
|
|
const response = await ai.models.generateContent({
|
|
model: "gemini-2.5-flash",
|
|
contents: promptText
|
|
});
|
|
|
|
const output = response.text || "";
|
|
|
|
const outPath = path.join(outputDir, "test.md");
|
|
fs.writeFileSync(outPath, output, "utf8");
|
|
|
|
console.log("Generated document written to:", outPath);
|
|
|
|
} catch (error) {
|
|
console.error("Error generating Gemini content:", error);
|
|
}
|
|
}
|
|
}; |