From 0415b37dc12d89d4d5e883f8322732095012c93b Mon Sep 17 00:00:00 2001 From: Shariq Date: Sat, 26 Oct 2024 15:51:56 +0530 Subject: [PATCH] Added Gemini AI Integration Interface --- package.json | 5 +++++ src/app/(pages)/api/generate/route.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/app/(pages)/api/generate/route.js diff --git a/package.json b/package.json index cba5840..a0d3a1d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,11 @@ "lint": "next lint" }, "dependencies": { + "@emotion/react": "^11.13.3", + "@emotion/styled": "^11.13.0", + "@google/generative-ai": "^0.21.0", + "@mui/icons-material": "^6.1.5", + "@mui/material": "^6.1.5", "@radix-ui/react-aspect-ratio": "^1.1.0", "@radix-ui/react-collapsible": "^1.1.1", "@radix-ui/react-dialog": "^1.1.2", diff --git a/src/app/(pages)/api/generate/route.js b/src/app/(pages)/api/generate/route.js new file mode 100644 index 0000000..0f7c501 --- /dev/null +++ b/src/app/(pages)/api/generate/route.js @@ -0,0 +1,17 @@ +import { GoogleGenerativeAI } from '@google/generative-ai'; + +const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY); + +export async function POST(req) { + const { prompt } = await req.json(); + try { + const model = genAI.getGenerativeModel({ model: 'gemini-pro' }); + const result = await model.generateContent(prompt); + const response = await result.response; + const generatedText = await response.text(); + + return new Response(JSON.stringify({ generatedText }), { status: 200 }); + } catch (error) { + return new Response(error.message, { status: 500 }); + } +}