|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
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 }; |