File size: 919 Bytes
984400f f6e09d2 984400f 8f02537 0d4c6be 984400f 8f02537 984400f 0d4c6be 760660f 984400f 0d4c6be 984400f 8f02537 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import { GoogleGenerativeAI } from "@google/generative-ai";
import * as config from './config.js';
if (!config.GoogleAPIKey) {
throw new Error("Missing variable: GOOGLE_API_KEY");
}
const genAI = new GoogleGenerativeAI(config.GoogleAPIKey);
/**
* Generate a response using the Gemini AI model.
* @param {string} prompt - The input string for the model.
* @returns {Promise<string>} The generated response text.
*/
async function GeminiResponse(prompt) {
try {
const model = genAI.getGenerativeModel({
model: "gemini-1.5-flash",
});
const result = await model.generateContent(prompt);
const text = result.response.candidates[0]?.content;
return text.parts[0].text || "No response content";
} catch (e) {
console.error(`Error in GeminiResponse: ${e.message}`);
return "Error generating response.";
}
}
export { GeminiResponse }; |