Skip to content

Abolfazl-Tabe-Bordbar/gemini_assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Google Generative AI Assistant API

This project is a simple server built with Node.js and Express that uses the @google/generative-ai library to generate text responses from Google Generative AI.

Prerequisites

To run this project, you need:

  • Node.js (version 14 or higher)
  • A valid API key from Google Gemini API

Installation and Setup

  1. Clone the repository or download the project files:
git clone <URL>
cd <project-directory>
  1. Install the required packages:
npm install
  1. Replace GEMINI_API_KEY with your own API key:
const GEMINI_API_KEY = "Your API key here";
  1. Start the server:
node index.js

The server will run on port 4000.

Usage

To send a request to the AI assistant:

  • Use tools like Postman or cURL.
  • Send a POST request to http://localhost:4000/assistant.

Request Format:

{
  "text": "Hello! How are you?"
}

Response Format:

{
  "data": "AI assistant response"
}

If no response is generated or an error occurs, an appropriate message will be returned.

AI Model Configuration

The following configurations are used to customize the AI model:

  • temperature: Controls the level of creativity in the response (0.7)
  • maxOutputTokens: Maximum length of the response (1024 tokens)
  • topP: Controls the range of word selection (0.9)

Error Handling and Invalid Requests

  • Any error that occurs during request processing is logged on the server, and an error message is sent back to the user.
  • For invalid routes, a 404 response with the message "This route is not in my API" will be returned.

Contributing

If you want to contribute, feel free to submit a Pull Request or open an Issue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published