|
import { GoogleGenerativeAI } from "@google/generative-ai"; |
|
import dotenv from "dotenv"; |
|
|
|
dotenv.config(); |
|
|
|
const GoogleAPIKey = process.env.GOOGLE_API_KEY; |
|
|
|
if (!GoogleAPIKey) { |
|
throw new Error("Missing variables GOOGLE_API_KEY"); |
|
} |
|
|
|
const genAI = new GoogleGenerativeAI(GoogleAPIKey); |
|
|
|
|
|
|
|
|
|
|
|
|
|
async function GeminiResponse(prompt) { |
|
try { |
|
const model = genAI.getGenerativeModel({ |
|
model: "gemini-1.5-flash", |
|
}); |
|
const result = await model.generateContent(prompt); |
|
console.log("Response", result) |
|
return result.response.text(); |
|
} catch (e) { |
|
console.error(`Error in GeminiResponse: ${e.message}`); |
|
return ""; |
|
} |
|
} |
|
|
|
export { GeminiResponse }; |