btch-gemini is a lightweight Node.js package for seamlessly interacting with the Gemini API. It provides simple, efficient methods for sending chat prompts, processing image descriptions, and handling various media types like audio and video with robust error handling.
- Node.js version 16 or higher
- An active internet connection
- API access to the Gemini service
Install the package using npm:
npm install btch-gemini
- 🤖
gemini_chat
: Send text prompts to the Gemini chat API - 🖼️
gemini_image
: Process image descriptions using text prompts and image URLs - 🎨
gemini_imgedit
: Edit image descriptions using text prompts and image URLs - 🎵
gemini_audio
: Process audio files from URLs - 🎥
gemini_video
: Analyze video files from URLs - 🧠
gemini_history
: Retrieve past interactions to continue conversations - 🔐 Comprehensive input validation
- 🚀 Easy-to-use asynchronous methods
const Gemini = require('btch-gemini');
import pkg from 'btch-gemini';
const Gemini = pkg;
async function chatExample() {
try {
const prompt = "Hello, how are you?";
const response = await Gemini.gemini_chat(prompt);
console.log(response);
} catch (error) {
console.error('Chat Error:', error.message);
}
}
async function imageExample() {
try {
const prompt = "What is this image about?";
const imageUrl = "https://files.catbox.moe/a13ppy.jpg";
const response = await Gemini.gemini_image(prompt, imageUrl);
console.log(response);
} catch (error) {
console.error('Image Processing Error:', error.message);
}
}
async function imageeditExample() {
try {
const prompt = "Transform this into a watercolor painting";
const imageUrl = "https://files.catbox.moe/a13ppy.jpg";
const response = await Gemini.gemini_imgedit(prompt, imageUrl);
console.log(response); // image buffer
} catch (error) {
console.error('Edit Image Error:', error.message);
}
}
async function audioExample() {
try {
const audioUrl = "https://files.catbox.moe/pj7g2g.opus"; // URL AUDIO
let prompt = "Please transcribe this audio"
const response = await Gemini.gemini_audio(audioUrl, prompt);
console.log(response);
} catch (error) {
console.error('Audio Processing Error:', error.message);
}
}
async function videoExample() {
try {
const videoUrl = "https://files.catbox.moe/4fozd2.mp4";
let prompt = "Please describe this video and transcribe the audio"
const response = await Gemini.gemini_video(videoUrl, prompt)
console.log(response);
} catch (error) {
console.error('Video Processing Error:', error.message);
}
}
async function historyExample() {
try {
const history = [
{ role: "user", content: "Hai! Nama saya Tio" },
{ role: "assistant", content: "Halo Tio, Senang bertemu dengan mu." },
{ role: "user", content: "Siapa nama saya yah jelaskan arti nama saya" }
];
const response = await Gemini.gemini_history(history);
console.log(response);
} catch (error) {
console.error('History Interaction Error:', error.message);
}
}
async function promptExample() {
try {
const systemPrompt = "This is a system instruction";
const query = "What is the meaning of life?";
const response = await Gemini.gemini_prompt(systemPrompt, query);
console.log(response);
} catch (error) {
console.error('Prompt Interaction Error:', error.message);
}
}
The package provides detailed error messages:
-
gemini_chat
: Validates prompt input -
gemini_image
: Validates both prompt and image URL -
gemini_audio
: Validates audio URL -
gemini_video
: Validates video URL -
gemini_history
: Ensures valid message structure -
gemini_prompt
: Validates prompt and query - Errors are thrown for invalid inputs or API communication issues
-
gemini_imgedit
: Validates both prompt and image URL
- Chat API:
https://gemini-api.zone.id/gemini/chat
- Image API:
https://gemini-api.zone.id/gemini/image
- Audio API:
https://gemini-api.zone.id/gemini/audio
- Video API:
https://gemini-api.zone.id/gemini/video
- Edit API:
https://gemini-api.zone.id/gemini/imgedit
- History API:
https://gemini-api.zone.id/gemini/history
- Prompt API:
https://gemini-api.zone.id/gemini/prompt
If you encounter any issues or have questions, please open an issue on GitHub.
Distributed under the MIT License. See LICENSE
for more information.