Files
video2document/services/modules/llm-gemini/gemini.js
T

55 lines
1.6 KiB
JavaScript

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);
}
}
};