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.
Install the package using npm:
npm install btch-gemini
gemini_chat
: Send text prompts to the Gemini chat APIgemini_image
: Process image descriptions using text prompts and image URLsgemini_imgedit
: Edit image descriptions using text prompts and image URLsgemini_audio
: Process audio files from URLsgemini_video
: Analyze video files from URLsgemini_history
: Retrieve past interactions to continue conversationsconst 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 inputgemini_image
: Validates both prompt and image URLgemini_audio
: Validates audio URLgemini_video
: Validates video URLgemini_history
: Ensures valid message structuregemini_prompt
: Validates prompt and querygemini_imgedit
: Validates both prompt and image URLhttps://gemini-api.zone.id/gemini/chat
https://gemini-api.zone.id/gemini/image
https://gemini-api.zone.id/gemini/audio
https://gemini-api.zone.id/gemini/video
https://gemini-api.zone.id/gemini/imgedit
https://gemini-api.zone.id/gemini/history
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.