mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
Test created and changes to gemini.js file
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
import fs from "fs";
|
||||
import { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
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
|
||||
});
|
||||
|
||||
const outputDir = `${__dirname}/../../../storage/documents`;
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: "llm-gemini",
|
||||
type: "llm",
|
||||
displayname: "Gemini LLM",
|
||||
description: "Generates documents using Google Gemini LLM",
|
||||
|
||||
async function(parameter) {
|
||||
try {
|
||||
@@ -25,7 +24,8 @@ module.exports = {
|
||||
|
||||
await this.createDocumentFromTranscript(
|
||||
parameter.inputTranscriptPath,
|
||||
parameter.documentType
|
||||
parameter.documentTypePath,
|
||||
parameter.language
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
@@ -33,23 +33,27 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
createDocumentFromTranscript: async function(transcriptPath, documentType) {
|
||||
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 text = `${documentType}\n\n${transcript}`;
|
||||
const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`;
|
||||
|
||||
const response = await ai.models.generateContent({
|
||||
model: "gemini-2.5-flash",
|
||||
contents: text
|
||||
contents: promptText
|
||||
});
|
||||
|
||||
const output = response.text ?? "";
|
||||
const output = response.text || "";
|
||||
|
||||
const outPath = path.join(outputDir, "test.md");
|
||||
fs.writeFileSync(outPath, output, "utf8");
|
||||
|
||||
console.log("Generated document written to:", outPath);
|
||||
|
||||
fs.writeFileSync(`${outputDir}/test.md`, output, "utf8");
|
||||
console.log("Generated document written to test.md");
|
||||
} catch (error) {
|
||||
console.error("Error generating content:", error);
|
||||
console.error("Error generating Gemini content:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user