npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

batao

v2.1.1

Published

This Node.js script interacts with Google's Gemini generative AI model to generate text content based on a given input prompt. The input prompt is read from a specified file, and the generated response is written to an output file.

Downloads

5

Readme

Batao: Your AI Assistant on the Command Line

Batao is a command-line interface (CLI) tool that allows you to interact with Google's powerful Gemini generative AI models directly from your terminal. Write stories, translate languages, generate code, and more!

Installation

sudo npm install -g batao

[!IMPORTANT]

Handling "fetch is not defined" Error

You might encounter a "fetch is not defined" error if your Node.js version is older than 18. Batao relies on @google/generative-ai, which requires Node.js 18 or later. Here's how to resolve this:

1. Install Node Version Manager (NVM):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Or follow the instructions for your operating system at https://github.com/nvm-sh/nvm

2. Reload Your Shell:

Close and reopen your terminal, or run:

source ~/.bashrc  

3. Install Node.js LTS:

nvm install --lts

4. Verify Node.js Version:

node -v

You should see a version number of 18 or higher.

Configuration

Before using Batao, you need to obtain a Google Generative AI API key.

  1. Get your API Key: Visit the Google Generative AI Console to get your key.
  2. First Run: Run batao in your terminal. You will be prompted to enter your API key, which will be saved securely in a configuration file (~/.batao/config.json).

Usage

batao [prompt] [options]

Prompt:

  • Provide your prompt directly as an argument:
    • Example: batao "Write a short story about a cat who goes on an adventure." - This will print the generated story to the terminal.
  • Read the prompt from a file using -i or --input.
    • Example: batao -i my_prompt.md - This will take input from my_prompt.md file and print the output to the terminal.

Options:

  • -m, --model <model>: Specify the Gemini model to use.
    • flash: (Default) Fastest and most lightweight.
    • pro: More powerful, suitable for complex tasks.
    • You can also use the full model names: gemini-1.5-flash, gemini-1.5-pro.
  • -t, --temperature <temperature>: Control the creativity of the output (0.0 - 1.0). Higher values result in more creative (and potentially less predictable) output. Default: 0.4
  • -i, --input <file>: Read the prompt from the specified file.
  • -o, --output <file>: Save the generated text to a file.
  • -r, --review <files...>: Review code files for logical issues, potential typos, and efficiency suggestions. Provide a space-separated list of file paths.
  • -a, --attachment <files...>: Attach additional files to the prompt for the AI model to consider. Provide a space-separated list of file paths.

[!TIP]

Using Markdown for Code and Rich Input:

You can significantly enhance your prompts by creating them in Markdown (.md) files. Here's why this is beneficial:

  • Code Embedding: Use code blocks to clearly present code to Batao for analysis, feedback, or modification.
    ```python
    def my_function():
        print("Hello from Python!")
    ```
  • Syntax Highlighting: Markdown supports syntax highlighting, making your code more readable for both you and Batao. This leads to more accurate code analysis and responses.
  • Structured Prompts: Create well-organized and detailed prompts using headings, lists, and other Markdown formatting elements.

Examples

1. Generate a creative story with the Pro model and save it to a file:

batao "A lonely robot on Mars discovers..." -m pro -t 0.7 -o my_story.txt

This command takes a prompt as input and uses the Pro model with a temperature of 0.7 to generate text. The output is then saved to a file named my_story.txt.

2. Translate text to Spanish with a lower temperature for more literal translation and print the output on terminal:

batao "Translate 'Hello, world!' to Spanish." -t 0.2

This command takes an English phrase as input and uses a lower temperature setting (0.2) to ensure a more accurate and less creative translation. The translated Spanish text is then displayed on the terminal.

3. Write Python code to a file:

batao "Write a Python function to calculate the factorial of a number." -o factorial.py

This command takes a prompt asking for a Python function that calculates factorials. The generated code will be saved into a file named factorial.py.

4. Generate ideas for a website with a higher temperature for more creative output and print the output on terminal:

batao "Give me some website ideas." -t 0.8

This command prompts the model to generate website ideas, setting the temperature to 0.8 to encourage more creative and unconventional suggestions. The ideas will be printed on the terminal.

5. Use input from a file and save output to another file:

batao -i prompt.txt -o output.txt

This command reads a prompt from a file named prompt.txt and saves the generated response to a file named output.txt.

6. Request code review for multiple files and get efficiency suggestions:

batao -r script.js style.css index.html -o review_results.txt

This command instructs batao to review the code in script.js, style.css, and index.html for potential improvements and provide feedback in the review_results.txt file.

7. Attach a data file to the prompt:

batao "Analyze the data in this file and generate a report." -a data.csv -o report.txt

This command instructs batao to analyze the data in data.csv and generate a report in report.txt.

[!TIP]

Gemini AI Models: Pro vs. Flash

Flash Model:

  • Use Cases: Best for quick tasks, simple content generation, and applications that require fast responses. Ideal for chatbots, lightweight code generation, and short translations.
  • Rate Limits: Typically has more generous rate limits, allowing for frequent requests.

Pro Model:

  • Use Cases: Suitable for complex reasoning, in-depth content creation, and tasks requiring higher accuracy and understanding. Use it for advanced code generation, long-form writing, and detailed research.
  • Rate Limits: May have stricter rate limits compared to the Flash model.

Use Cases for Programmers

Batao can be an invaluable tool for programmers:

  • Code Feedback: Ask Batao to review your code by providing it within a markdown file using code blocks or by using the -r flag. Get suggestions for improvement, potential errors to look for, and best practice reminders.
  • Debugging Help: Describe the bug you're encountering along with relevant code snippets in a file. Batao can help identify the source of the problem and may even suggest solutions.
  • Practice Coding Challenges: Ask Batao to create programming challenges for you. This is a great way to solidify concepts and prepare for technical interviews.
  • Code Explanation: Don't understand a concept or block of code? Ask Batao to explain it in simpler terms by putting the code in a Markdown file and adding your question as a prompt. This is like having an instant coding tutor.
  • Prototype Ideas Quickly: Test out new ideas or concepts quickly by asking Batao to generate basic code structures.
  • Summarize Notes: Have lengthy code comments or technical documentation? Ask Batao to summarize them for you to quickly grasp the key information.

Contributing

Contributions are welcome! Please feel free to open issues and submit pull requests to help improve Batao.