btch-gemini

btch-gemini Unofficial Module

Description

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.

Prerequisites

Installation

Install the package using npm:

npm install btch-gemini

Features

Usage

Import the Package

const Gemini = require('btch-gemini');

ESM

import pkg from 'btch-gemini';
const Gemini = pkg;

Chat Interaction

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);
    }
}

Image Processing

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);
    }
}

Image Edit

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);
    }
}

Audio Processing

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);
    }
}

Video Processing

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);
    }
}

History Interaction

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);
    }
}

System Prompt and Query

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);
    }
}

Error Handling

The package provides detailed error messages:

API Endpoints

Support

If you encounter any issues or have questions, please open an issue on GitHub.

License

Distributed under the MIT License. See LICENSE for more information.