π€ This project is the backend API server for the Gemini AI Chatbot, which provides specialized support for inquiries related to Thiago Bardini's professional career. Engineered with Gemini AI, this chatbot backend connects to a MongoDB database to retrieve initial data and is configured to run in a Node.js environment.
- Node.js: Asynchronous, event-driven JavaScript runtime.
- Express.js: Web framework for Node.js, used to build the server API.
- Google Generative AI: AI technology used to generate predictive responses.
- MongoDB: NoSQL database used to store initial and configuration data.
- dotenv: Module to load environment variables from a
.env
file. - Nodemon: Tool that automatically restarts the Node.js server on file changes.
- Node.js (version 18.x or higher)
- MongoDB Atlas or a local MongoDB instance
- Google Cloud account to access the Google Generative AI API
-
Clone this repository:
git clone [email protected]:thiagobardini/api-chat-server.git
-
Install project dependencies:
pnpm install
-
Create a
.env
file in the project root with the following environment variables:GEMINI_API_KEY="your-google-generative-ai-api-key" PORT=8000 NODE_ENV="development" MONGODB_URI="your-mongodb-connection-uri"
-
Start the server:
pnpm start
The server will run on the port defined in the .env
file (default is 3000).
.
βββ api/
β βββ index.js # Main file for the Express server
βββ db.js # MongoDB connection and data retrieval functions
βββ .env # Environment variables configuration file
βββ package.json # Project dependencies and scripts
βββ README.md # Project documentation
βββ ... # Other project files
Default route to check if the server is running.
- URL:
/
- HTTP Method:
GET
- Response:
Express on Vercel
Test route to retrieve initial text from MongoDB.
- URL:
/test-fetch-text
- HTTP Method:
GET
- Response:
Retrieved text: <text>
Main route to interact with the chatbot.
-
URL:
/chat-with-gemini
-
HTTP Method:
POST
-
Request Body:
{ "message": "your message", "history": [ { "role": "user", "parts": [{ "text": "previous message" }] } ] }
-
Response: Text generated by Google Generative AI
To deploy the project to Heroku, use the following commands:
git add .
git commit -m "message"
# if not logged in
heroku login
git push heroku main
# if add new text to MongoDB run the restart command
heroku restart -a chat-box-portfolio
heroku logs --tail -a chat-box-portfolio
heroku open -a chat-box-portfolio
If you wish to contribute to this project, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
- Website: https://www.tbardini.com/
- Frontend Configuration: Frontend Configuration