Test created and changes to gemini.js file

This commit is contained in:
MikeHughes-BIN
2025-11-18 19:16:51 +01:00
parent 8e7e0b5043
commit a1d804f463
5 changed files with 121 additions and 18 deletions
+22 -18
View File
@@ -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);
}
}
};