/* * Install the Generative AI SDK * * $ npm install @google/generative-ai * * See the getting started guide for more information * https://ai.google.dev/gemini-api/docs/get-started/node */ const { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold, } = require("@google/generative-ai"); const { GoogleAIFileManager } = require("@google/generative-ai/files"); const apiKey = process.env.GEMINI_API_KEY; const genAI = new GoogleGenerativeAI(apiKey); const fileManager = new GoogleAIFileManager(apiKey); /** * Uploads the given file to Gemini. * * See https://ai.google.dev/gemini-api/docs/prompting_with_media */ async function uploadToGemini(path, mimeType) { const uploadResult = await fileManager.uploadFile(path, { mimeType, displayName: path, }); const file = uploadResult.file; console.log(`Uploaded file ${file.displayName} as: ${file.name}`); return file; } const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash...