Skip to content

david-crespo/llm-cli

Repository files navigation

llm-cli

A simple but full-featured CLI powered by Deno for chatting with LLMs. A few hundred lines of TypeScript in a single file.

Thanks to Justin Bennett for the script that inspired this as well as the idea of piping markdown output to glow.

image

Features

Supports GPT and Claude

image

Beautiful output powered by markdown

image

Continue chat with replies

image

Read input from stdin

image

Upload chat to GitHub Gist for sharing or permanent storage

https://gist.github.com/david-crespo/a2bf06be5db310db967b2e35f6140da2

image

Limitations

No vision, no streaming responses (yet).

Setup

API keys

Set any or all of these, depending on which models you want to use. It is often convenient to put them in a .env file like below and call source .env.

export OPENAI_API_KEY=abc-123
export ANTHROPIC_API_KEY=def-456
export GEMINI_API_KEY=ghi-789

The script does not automatically pick up a .env file; the variables need to be set in the environment.

Dependencies

  • Deno (essential)
  • glow (terminal markdown renderer)
    • You can do without glow if you like reading raw markdown or you pipe output to some other tool for rendering markdown in the terminal
  • gh (GitHub CLI, optional)
    • Only needed if you want to upload chats as GitHub gists
    • You'll need to be logged in (gh auth login)

Installation

Clone the repo. Then you just need a way to run main.ts and pipe the output to glow. I use this function in my .zprofile:

function ai() {
  source ~/path/to/.env
  ~/repos/llm-cli/main.ts "$@"
}

The "$@:" means pipe all command-line arguments to ai straight to main.ts.

You'll need to chmod +x the script in order to be able to execute it directly like above. Otherwise, you could run it with deno run path/to/main.ts, but that is less convenient because you'll have to set all the permissions I've set in the shebang line.

Contributions

This is mostly for me (though I'd be thrilled if people find it useful), so I'm not really interested in changes that make this tool more general-purpose unless a) I want to use them, b) they don't make the interface any more complicated. The open issues include features I'd be interested in adding.

About

A simple CLI for using LLM APIs

Resources

License

Stars

Watchers

Forks