mods

repository·main·Indexed 26 days ago

https://github.com/charmbracelet/mods

An AI tool for the command line designed for pipelines. Mods allows users to ingest command output and use LLMs to format, summarize, or transform data into Markdown, JSON, and other formats. It supports multiple providers including OpenAI, Azure OpenAI, Cohere, Groq, Gemini, and LocalAI, and includes features for conversation management, custom roles, and Model Context Protocol (MCP) server integration.

Tokens
5.8K
Snippets
18
Records
43
Agent score
88%

What's inside mods

  1. Use Mods in your command line

    main
    Mods works by reading standard input (stdin) and combining it with a prompt provided in the arguments. It sends the text to an LLM and prints the result. You can pipe command output directly into mods to 'question' it.
  2. Continue from a specific conversation and branch

    main
    To branch a conversation, use --continue with the title of an existing conversation and provide a new --title. This allows you to create multiple different paths from the same starting point.
  3. Configure API keys for LLM providers

    main

    Mods supports multiple LLM providers. To use them, set the corresponding environment variable:

    • OpenAI: OPENAI_API_KEY (Defaults to GPT-4, falls back to GPT-3.5 Turbo)
    • Azure OpenAI: AZURE_OPENAI_KEY
    • Cohere: COHERE_API_KEY
    • Groq: GROQ_API_KEY
    • Gemini: GOOGLE_API_KEY

    Mods also supports LocalAI running on port 8080 by default. You can configure additional endpoints by running mods --settings to open the settings file.

  4. List, show, and delete conversations

    main

    Manage your conversation history using the following commands:

    • List all: Use --list or -l to see previous conversations.
    • Show a conversation: Use --show='title' (exact match required) or --show='id' (the first 4 characters of the ID are sufficient to identify a unique conversation).
    • Delete a conversation: Use --delete='title' or --delete='id'. These operations are irreversible. You can use the flag multiple times to delete several conversations at once.
    # List conversations
    mods --list
    # or
    mods -l
    
    # Show a conversation by title or ID
    mods --show='naturals'
    mods -s='a2e2'
    
    # Delete conversations (irreversible)
    mods --delete='naturals' --delete='a2e2'
  5. Basic usage of mods

    main

    The simplest way to use mods is to provide a prompt string directly. By default, all messages are sent to STDERR, prompts are saved using the first line of the prompt as the title, and glamour is used for formatting if STDOUT is a TTY.

    mods 'first 2 primes'
  6. Install Mods

    main

    You can install Mods using various package managers depending on your operating system:

    • macOS or Linux: Use Homebrew.
    • Windows: Use Winget.
    • Arch Linux: Use yay.
    • Nix: Use nix-shell.
    • Debian/Ubuntu: Add the Charm repository and use apt.
    • Fedora/RHEL: Add the Charm repository and use yum.
    • FreeBSD: Install from ports.
    • Go: Install via go install.

    If you build from source, you can generate shell completions for Bash, ZSH, Fish, and PowerShell using the mods completion command.

    # macOS or Linux
    brew install charmbracelet/tap/mods
    
    # Windows (with Winget)
    winget install charmbracelet.mods
    
    # Arch Linux (btw)
    yay -S mods
    
    # Nix
    nix-shell -p mods
    
    # Go
    go install github.com/charmbracelet/mods@latest
  7. Continue the latest conversation

    main

    You can extend your most recent conversation using two different methods:

    1. Continue and rename: Use --continue='new_title' to continue the last conversation and save it under a new name.
    2. Continue without renaming: Use --continue-last to continue the last conversation without changing the title.
    # Continue and save with a new title
    mods 'first 2 primes'
    mods --continue='primes as json' 'format as json'
    
    # Continue the last conversation as-is
    mods 'first 2 primes'
    mods --continue-last 'format as json'
  8. Define and use Custom Roles

    main

    Roles allow you to set system prompts for specific tasks. You can define roles in your settings file using YAML.

    Example role definition for a shell expert:

    roles:
      shell:
        - you are a shell expert
        - you do not explain anything
        - you simply output one liners to solve the problems you're asked
        - you do not provide any explanation whatsoever, ONLY the command

    To use the role, pass the --role flag:

    mods --role shell list files in the current directory
  9. Pipe output from mods

    main

    You can pipe the output of mods to another program. When STDOUT is not a TTY (e.g., when piping), the "Generating" animation is automatically redirected to STDERR so that only the response is streamed to STDOUT.

    echo 'as json' | mods 'first 2 primes' | jq .
  10. Use the mods CLI for GPT in pipelines

    main
    The mods CLI provides a way to interact with GPT models directly from the command line, designed specifically for use in shell pipelines. You can pass prompts as command-line arguments or pipe input from STDIN.
  11. Manage mods configuration and settings

    main

    You can manage your mods configuration and cache locations using the following commands:

    • Edit Settings: Use the --settings flag to open your configuration file in your default $EDITOR.
    • Reset Settings: Use the --reset-settings flag to restore settings to their defaults (this creates a .bak backup of your old config).
    • View Directories: Use the --dirs flag to see your configuration and cache paths.
      • mods --dirs config: Shows the configuration directory.
      • mods --dirs cache: Shows the cache directory.
    • List Roles: Use the --list-roles flag to see available custom roles.