Skip to content

Latest commit

 

History

History
147 lines (99 loc) · 3.63 KB

README.md

File metadata and controls

147 lines (99 loc) · 3.63 KB

Demo Report Logo


Chatbot API Server

Description

🤖 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.

Technologies Used

  • 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.

Installation

Prerequisites

  • Node.js (version 18.x or higher)
  • MongoDB Atlas or a local MongoDB instance
  • Google Cloud account to access the Google Generative AI API

Steps

  1. Clone this repository:

    git clone git@github.com:thiagobardini/api-chat-server.git
  2. Install project dependencies:

    pnpm install
  3. 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"
    
  4. Start the server:

    pnpm start

The server will run on the port defined in the .env file (default is 3000).

Project Structure

.
├── 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

Endpoints

GET /

Default route to check if the server is running.

  • URL: /
  • HTTP Method: GET
  • Response: Express on Vercel

GET /test-fetch-text

Test route to retrieve initial text from MongoDB.

  • URL: /test-fetch-text
  • HTTP Method: GET
  • Response: Retrieved text: <text>

POST /chat-with-gemini

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

Heroku Commands

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

Contribution

If you wish to contribute to this project, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Links