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.
To run this project, you need:
- Node.js (version 14 or higher)
- A valid API key from Google Gemini API
- Clone the repository or download the project files:
git clone <URL>
cd <project-directory>
- Install the required packages:
npm install
- Replace
GEMINI_API_KEY
with your own API key:
const GEMINI_API_KEY = "Your API key here";
- Start the server:
node index.js
The server will run on port 4000.
To send a request to the AI assistant:
- Use tools like
Postman
orcURL
. - Send a
POST
request tohttp://localhost:4000/assistant
.
{
"text": "Hello! How are you?"
}
{
"data": "AI assistant response"
}
If no response is generated or an error occurs, an appropriate message will be returned.
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)
- 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.
If you want to contribute, feel free to submit a Pull Request or open an Issue.