Added comments to my code to make it more understandable

This commit is contained in:
MikeHughes-BIN
2025-11-18 19:53:19 +01:00
parent 75a454ad60
commit a178ccf30f
+14 -14
View File
@@ -1,15 +1,15 @@
const fs = require("fs");
const path = require("path");
const { GoogleGenAI } = require("@google/genai");
const { GoogleGenAI } = require("@google/genai"); // Import Google Gemini AI SDK
const outputDir = path.join(__dirname, "../../../storage/documents");
const outputDir = path.join(__dirname, "../../../storage/documents"); // path for output directory
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
fs.mkdirSync(outputDir, { recursive: true }); // Create output directory if it doesn't exist
}
const ai = new GoogleGenAI({
apiKey: process.env.GOOGLE_API_KEY
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 = {
@@ -22,10 +22,10 @@ module.exports = {
try {
console.log("Gemini LLM module invoked with parameters:", parameter);
await this.createDocumentFromTranscript(
parameter.inputTranscriptPath,
parameter.documentTypePath,
parameter.language
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) {
@@ -33,7 +33,7 @@ module.exports = {
}
},
createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") {
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");
@@ -41,14 +41,14 @@ module.exports = {
const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`;
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: promptText
model: "gemini-2.5-flash", // Specify the Gemini model to use
contents: promptText // Input prompt for content generation
});
const output = response.text || "";
const output = response.text || ""; // Get generated text from response or default to empty string (if null)
const outPath = path.join(outputDir, "test.md");
fs.writeFileSync(outPath, output, "utf8");
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);