AI Shell

repository·main·Indexed 26 days ago

https://github.com/builderio/ai-shell

A command-line interface (@builder.io/ai-shell) that converts natural language prompts into executable shell commands. It provides an interactive workflow to run, revise, or cancel scripts, and includes a conversational chat mode. Key features include a configuration UI, silent mode to skip explanations, and support for multiple response languages.

Tokens
2.9K
Snippets
10
Records
32
Agent score
87%

What's inside ai-shell

  1. Enable Silent Mode

    main

    To skip the explanation section and only receive the command, use the -s or --silent flag. You can also make this a permanent preference.

    One-time use:

    ai -s 列出所有日志文件

    Set as permanent preference:

    ai config set SILENT_MODE=true
  2. Install AI Shell

    main

    Install the ai-shell CLI globally using npm. Requires Node.js v14 or higher.

    1. Install the package:
      npm install -g @builder.io/ai-shell
    2. Obtain an API key from OpenAI.
    3. Configure your key:
      ai config set OPENAI_KEY=<your token>
      This creates a .ai-shell configuration file in your home directory.
    npm install -g @builder.io/ai-shell
    
    ai config set OPENAI_KEY=<your token>
  3. Use AI Shell to generate commands

    main

    To convert a natural language prompt into a shell command, use the ai command followed by your prompt.

    Basic Usage:

    ai <prompt>

    Example:

    ai list all log files

    After running a prompt, the CLI will provide the suggested script and an explanation. You can then choose to:

    • Yes: Run the script.
    • Revise: Edit the command via a new prompt.
    • Cancel: Abort the operation.

    Tip: If your prompt contains special characters like ? or * that your shell might interpret incorrectly, wrap the prompt in quotes:

    ai 'what is my ip address'
  4. Configure AI Shell settings

    main

    You can manage configuration via the CLI or an interactive UI.

    Interactive UI: Run the following command to open a visual interface to set options like OpenAI Key, API Endpoint, Silent Mode, Model, and Language:

    ai config

    Manual Configuration via CLI: Use ai config set <KEY>=<VALUE> to update specific settings.

  5. Install and Setup AI Shell

    main

    AI Shell is a CLI that converts natural language to shell commands. It requires Node.js v14 or higher.

    1. Install the package globally via npm:
      npm install -g @builder.io/ai-shell
    2. Obtain an OpenAI API key from OpenAI.
    3. Configure the key in AI Shell:
      ai config set OPENAI_KEY=<your token>
      This creates a .ai-shell file in your home directory.
    npm install -g @builder.io/ai-shell
    ai config set OPENAI_KEY=<your token>
  6. Configure Silent Mode to skip explanations

    main

    To disable the explanation section in the output, you can use the --silent flag for a single command or set it as a permanent preference.

    One-time use:

    ai -s <prompt>
    # or
    ai --silent <prompt>

    Permanent setting:

    ai config set SILENT_MODE=true
    ai -s list all log files
  7. Configure AI Shell settings via CLI or UI

    main

    You can manage your configuration using the ai config command.

    Interactive UI

    To open an interactive visual interface to view and set options (like OpenAI Key, Model, or Language), run:

    ai config

    Command Line Configuration

    You can set specific keys directly using ai config set <KEY>=<VALUE>. Supported configuration keys include:

    • OPENAI_KEY: Your OpenAI API token.
    • SILENT_MODE: Set to true to skip command explanations.
    • OPENAI_API_ENDPOINT: Custom OpenAI API endpoint (defaults to https://api.openai.com/v1).
    • LANGUAGE: The language for AI responses (e.g., en, zh-Hans, es).
  8. Use the interactive configuration UI

    main

    AI Shell provides an interactive menu to view and update your settings. This UI allows you to:

    • Enter or update your OPENAI_KEY.
    • Change the OPENAI_API_ENDPOINT.
    • Toggle SILENT_MODE on or off.
    • Select a model from a list of available models fetched from your API endpoint.
    • Change the interface LANGUAGE.
    • View current values (with the API key obfuscated).
  9. Troubleshoot OpenAI 429 errors

    main

    If you encounter a 429 error, it typically indicates that you have exceeded your OpenAI quota or have an incorrect billing setup.

    To resolve this:

    1. Check your usage and billing status at OpenAI Billing.
    2. Ensure a valid payment method is attached if you are not using an active grant.