Bestie API is an AI-powered assistant built with Node.js and Express that interacts with Google's Generative AI models. It provides endpoints for text and image analysis, leveraging the capabilities of the Gemini model.
-
Node.js (version 20 or higher)
-
npm (Node Package Manager)
-
Google Cloud Account with access to the Generative AI API
-
Google Generative AI API Key
- Clone the repository:
git clone https://github.com/fikri2992/bestie-api
cd bestie-api
- Install dependencies:
npm install
- Create a
.env
file in the root directory:
touch .env
- Add your Google Generative AI API key to the
.env
file:
GEMINI_API_KEY=YOUR_GOOGLE_GENERATIVE_AI_API_KEY
Replace YOUR_GOOGLE_GENERATIVE_AI_API_KEY
with your actual API key.
Start the server using the following command:
node gemini.js
Process a text message and receive a response from Bestie.
-
URL:
/api/message
-
Method:
POST
-
Headers:
Content-Type: application/json
-
Body:
{ "text": "Your message here", "history": [] }
text
: (string) The message you want to send to Bestie.history
: (array) An array of previous messages for context (optional). Response:
{ "type": "text", "message": "Bestie's response", "stepsToDo": [...], "contextFromHistory": [...], "emotionalReactions": [...], ... }
Upload two images for analysis.
-
URL:
/img-bestie
-
Method:
POST
-
Headers:
Content-Type: multipart/form-data
-
Body:
image
: (file) The first image file.screenshot
: (file) The second image file.
-
Response:
{ "type": "text", "message": "Analysis result", "isInappropriate": true, "type": "Type of content identified", "sentiment": "negative", ... }
Upload a screenshot and text for analysis.
-
URL:
/wdyt-bestie
-
Method:
POST
-
Headers:
Content-Type: multipart/form-data
-
Body:
text
: (string) The text message.screenshot
: (file) The screenshot file.
-
Response:
{ "type": "text", "message": "Analysis result", "isInappropriate": false, "type": "manipulation", "sentiment": "neutral", ... }
curl -X POST http://localhost:3000/api/message \
-H "Content-Type: application/json" \
-d '{
"text": "Hello Bestie!",
"history": []
}'
curl -X POST http://localhost:3000/img-bestie \
-F "image=@/path/to/first_image.jpg" \
-F "screenshot=@/path/to/second_image.jpg"
curl -X POST http://localhost:3000/wdyt-bestie \
-F "text=Some text message" \
-F "screenshot=@/path/to/screenshot.jpg"
This project is licensed under the MIT License.
-
Dependencies: Make sure all the dependencies listed in
package.json
are installed. These include:express
http
sharp
uuid
fs
path
@google/generative-ai
multer
dotenv
-
API Key: To obtain the
GEMINI_API_KEY
, you need access to Google's Generative AI APIs. Follow Google's documentation to set up an API key with the necessary permissions. -
Environment Variables: The application uses environment variables defined in the
.env
file. BesidesGEMINI_API_KEY
, ensure any other necessary environment variables are also defined. -
Error Handling: The server includes error handling for various scenarios, such as missing files or invalid inputs. Check the console output for detailed error messages during development.
-
Uploads Directory: Uploaded files are temporarily stored in the
uploads/
directory. The application attempts to delete processed files after they are used. Ensure the application has the necessary permissions to read from and write to this directory.
Disclaimer: Use this project responsibly and adhere to all applicable laws and terms of service for the APIs and services used.