mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
c2f22b3525
included the requires libraries in the package.json implemented the library into requires.js cleaned up ffmpeg from the events
55 lines
2.4 KiB
JavaScript
55 lines
2.4 KiB
JavaScript
const outputDir = path.join(__dirname, "../../../storage/documents"); // path for output directory
|
|
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true }); // Create output directory if it doesn't exist
|
|
}
|
|
|
|
const ai = new genai.GoogleGenAI({
|
|
apiKey: process.env.GOOGLE_API_KEY // Ensure Google API key is set in environment variables: export GOOGLE_API_KEY="your_api_key_here"
|
|
});
|
|
|
|
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( //Call the function to create document with transcript, document type and language
|
|
parameter.inputTranscriptPath, // Path to input transcript file
|
|
parameter.documentTypePath, // Path to document type file which is chosen in the front end by the user
|
|
parameter.language // Language for the document which is chosen in the front end by the user
|
|
);
|
|
|
|
} catch (error) {
|
|
console.error("Error in Gemini LLM module:", error);
|
|
}
|
|
},
|
|
|
|
createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") { // default language is English
|
|
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", // Specify the Gemini model to use
|
|
contents: promptText // Input prompt for content generation
|
|
});
|
|
|
|
const output = response.text || ""; // Get generated text from response or default to empty string (if null)
|
|
|
|
const outPath = path.join(outputDir, "test.md"); // Output file path & name TO BE DONE to make dynamic out of input transcript name
|
|
fs.writeFileSync(outPath, output, "utf8"); // Write output to file
|
|
|
|
console.log("Generated document written to:", outPath);
|
|
|
|
} catch (error) {
|
|
console.error("Error generating Gemini content:", error);
|
|
}
|
|
}
|
|
}; |