randydev commited on
Commit
984400f
·
verified ·
1 Parent(s): 70335fc

Create googleGemini.js

Browse files
Files changed (1) hide show
  1. googleGemini.js +33 -0
googleGemini.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { GoogleGenerativeAI } from "@google/generative-ai";
2
+ import dotenv from "dotenv";
3
+
4
+ dotenv.config();
5
+
6
+ const GoogleAPIKey = process.env.GOOGLE_API_KEY;
7
+
8
+ if (!GoogleAPIKey) {
9
+ throw new Error("Missing variables GOOGLE_API_KEY");
10
+ }
11
+
12
+ const genAI = new GoogleGenerativeAI(GoogleAPIKey);
13
+
14
+ /**
15
+ * Generate a response using the Gemini AI model.
16
+ * @param {string} prompt - The input string for the model.
17
+ * @returns {Promise<string>} The generated response text.
18
+ */
19
+ async function GeminiResponse(prompt) {
20
+ try {
21
+ const model = genAI.getGenerativeModel({
22
+ model: "gemini-1.5-flash",
23
+ });
24
+ const result = await model.generateContent(prompt);
25
+ console.log("Response", result)
26
+ return result.response.text();
27
+ } catch (e) {
28
+ console.error(`Error in GeminiResponse: ${e.message}`);
29
+ return "";
30
+ }
31
+ }
32
+
33
+ export { GeminiResponse };