llm README

The project's README from github.com/simonw/llm. As one markdown file: README.md.

LLM

GitHub repo PyPI Changelog Tests License Discord Homebrew

A CLI tool and Python library for interacting with OpenAI, Anthropic’s Claude, Google’s Gemini, Qwen, Gemma, Kimi, DeepSeek, Mistral, and dozens of other Large Language Models, both via remote APIs and with models that can be installed and run on your own machine.

Watch Language models on the command-line on YouTube for a demo or read the accompanying detailed notes.

With LLM you can:

Quick start

First, install LLM using pip or Homebrew or pipx or uv:

pip install llm

Or with Homebrew (see warning note):

brew install llm

Or with pipx:

pipx install llm

Or with uv

uv tool install llm

Use LLM to run prompts or start chats against an arbitrary OpenAI-compatible Chat Completions endpoint, such as LM Studio. With uvx, you can do this without installing LLM first:

uvx llm openai endpoint http://localhost:1234/v1 \
  -m google/gemma-4-12b \
  "What is the capital of France?"

uvx llm openai endpoint http://localhost:1234/v1 \
  -m google/gemma-4-12b \
  --chat

Add --key your-api-key if the endpoint requires authentication. See Run against an endpoint without configuring it for more options.

If you have an OpenAI API key key you can run this:

# Paste your OpenAI API key into this
llm keys set openai

# Run a prompt (with the default gpt-5.6-luna model)
llm "Ten fun names for a pet pelican"

# Extract text from an image
llm "extract text" -a scanned-document.jpg

# Use a system prompt against a file
cat myfile.py | llm -s "Explain this code"

Run prompts against Gemini or Anthropic with their respective plugins:

llm install llm-gemini
llm keys set gemini
# Paste Gemini API key here
llm -m gemini-3.5-flash 'Tell me fun facts about Mountain View'

llm install llm-anthropic
llm keys set anthropic
# Paste Anthropic API key here
llm -m claude-sonnet-5 'Impress me with wild facts about turnips'

You can also install a plugin to access models that can run on your local device. If you use Ollama:

# Install the plugin
llm install llm-ollama

# Download and run a prompt against the Orca Mini 7B model
ollama pull llama3.2:latest
llm -m llama3.2:latest 'What is the capital of France?'

To start an interactive chat with a model, use llm chat:

llm chat -m gpt-4.1
Chatting with gpt-4.1
Type 'exit' or 'quit' to exit
Type '!multi' to enter multiple lines, then '!end' to finish
Type '!edit' to open your default editor and modify the prompt.
Type '!fragment <my_fragment> [<another_fragment> ...]' to insert one or more fragments
> Tell me a joke about a pelican
Why don't pelicans like to tip waiters?

Because they always have a big bill!

Project news

For everything else, see the llm tag on my blog.

Contents

llm (simonw/llm)

Searching Database…

12.6K ·GitHub
这是什么?LLM 是一个命令行工具和 Python 库,可用于向 OpenAI、Anthropic Claude、Google Gemini、Qwen、Gemma、Kimi、DeepSeek、Mistral 以及数十种其他大语言模型发送提示词,既可以通过远程 API 调用,也可以在你自己的电脑上本地运行模型。
这是命令行工具还是 Python 库?两者都是:你可以使用 `llm` 命令行工具运行提示词和对话,也可以在自己的代码中通过 Python API 执行提示词、生成嵌入向量、使用结构化模式以及管理对话。
我该如何安装并开始运行提示词?用 pip、Homebrew、pipx 或 uv 安装,如有需要再添加 API 密钥(例如 `llm keys set openai`),然后运行 `llm '你的提示词'`,或者用 `llm chat` 进入交互式会话。Ollama 等本地模型插件也可以按同样的方式安装和使用。
每个想用的模型都需要 API 密钥吗?使用 OpenAI 等托管服务商的模型需要 API 密钥(可以通过 `--key your-api-key` 指定,或用 `llm keys set` 保存);而通过 Ollama 等插件安装的本地模型则不需要密钥。
每个模型服务商都需要单独安装插件吗?是的。除了内置的 OpenAI 支持之外,Gemini、Claude 以及本地后端等模型都需要安装各自对应的 LLM 插件。
我可以在 macOS、Linux 和 Windows 上使用吗?可以。它是一个 Python 包,可以通过 pip、pipx 或 uv 安装(macOS 上也可以用 Homebrew),只要有 Python 或 uv 的地方就能跨平台运行。
我的提示词和回复会保存在哪里?默认情况下,每条提示词和回复都会记录到你电脑上的本地 SQLite 数据库中。你可以直接查询,也可以用 Datasette 浏览,或者选择关闭这项记录。
它能使用工具或函数调用吗?可以。LLM 支持让模型调用工具,内置了一组默认工具,并提供了实现自定义工具的文档。
我能提取结构化数据,而不只是纯文本吗?可以。LLM 支持使用 JSON 模式,从非结构化的文本或图片中提取结构化内容,采用简洁的模式语法,并支持可复用的模板。
它能生成并搜索嵌入向量吗?可以。`llm embed`、`llm embed-multi` 和 `llm similar` 等命令可以让你生成、存储和搜索嵌入向量,结果会保存在 SQLite 的集合中。
我能对接 LM Studio 这类兼容 OpenAI 的接口吗?可以。你可以将 LLM 指向任何兼容 OpenAI Chat Completions 的接口(例如 LM Studio),无需预先配置即可运行提示词,甚至可以在不先安装 LLM 的情况下通过 `uvx` 使用。
Creator
simonw
Size
2.4 MB
Stars
12.6K
Age
3y
Commits · 90 Days