ryu-js / googleGemini.js
randydev's picture
Update googleGemini.js
02b7f1c verified
raw
history blame
836 Bytes
import { GoogleGenerativeAI } from "@google/generative-ai";
import * as config from './config.js';
const genAI = new GoogleGenerativeAI(config.GoogleAPIKey);
/**
* @param {string} prompt - The input string for the model.
* @param {string} setModel - you can change the model
* @returns {Promise<string>} The generated response text.
*/
async function GeminiResponse(prompt, setModel) {
try {
const model = genAI.getGenerativeModel({
model: setModel,
});
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 };