Skip to content

Conversation

@Riya-chandra
Copy link
Contributor

@Riya-chandra Riya-chandra commented Sep 3, 2025

Pull Request: Gemini API Integration (Frontend + Backend)

Description

This PR integrates Gemini AI API into both the backend and frontend of the project.
It allows chatbot-like interactions through Gemini’s service with proper request handling, secure API key usage, and frontend components for a smooth user experience.

Issue no. #118

Changes Implemented

Backend
Created services/geminiAi.js for handling API communication with Gemini.
Added a new route:
POST /api/chatai → Accepts user messages, sends them to Gemini API, and returns AI response.
Implemented error handling to gracefully manage missing/invalid inputs.
Frontend
Added chatbot UI with input + output rendering.
Connected frontend to backend route /api/chatai.
Implemented loading state + error messages for better UX.
Styled using Tailwind + popup hint for chatbot icon.

Setup Instructions

Add a .env file in the root directory with the following variable:

GEMINI_API_KEY=YOUR_GEMINI_KEY...make sure to add the key in GeminiService.ts file in backend

Ensure the API key is correctly referenced in geminiAi.js (backend service).
Without this, the service will crash.

Run backend + frontend together:

Backend

npm run dev

Frontend

npm start

##Video
https://github.com/user-attachments/assets/205875df-f242-428f-ad51-bbeaf2b5b7c9

##backend .env
GEMINI_API_KEY=YOUR_API_KEY
CORS_ORIGIN=http://localhost:5173
PORT=4000

##frontend .env
VITE_API_BASE_URL=http://localhost:3000

##Important Notes regarding this PR
Example .env file structure is provided above—developers need to fill in their own key.
If the GEMINI_API_KEY is missing, backend requests will fail with error.

Riya Chandra || GSSOC Contributor 2025
Thank you !
@Kushika-Agarwal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant