ITADN
simonw/llm
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

LLM

GitHub repo PyPI Changelog Tests License Discord Homebrew

一个用于与 OpenAIAnthropic’s ClaudeGoogle’s GeminiQwenGemmaKimiDeepSeekMistral 以及数十种其他大型语言模型进行交互的 CLI 工具和 Python 库,既支持通过远程 API,也支持在本地机器上安装和运行的模型。

在 YouTube 上观看 Language models on the command-line 以查看演示,或阅读配套详细笔记

使用 LLM,你可以:

快速开始

首先,使用 pip 或 Homebrew 或 pipxuv 安装 LLM:

pip install llm

或者使用 Homebrew(参见警告说明]):

brew install llm

或者使用 pipx:

pipx install llm

或者使用 uv

uv tool install llm

使用 LLM 针对任意兼容 OpenAI 的 Chat Completions 端点(例如 LM Studio)运行提示词或启动聊天。借助 uvx,你可以在不先安装 LLM 的情况下完成此操作:

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

如果端点需要身份验证,请添加 --key your-api-key。有关更多选项,请参阅 Run against an endpoint without configuring it

如果你有一个 OpenAI API key 密钥,可以运行以下命令:

# 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"

使用各自的插件,针对 GeminiAnthropic 运行提示词:

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'

你也可以安装插件以访问可在本地设备上运行的模型。如果你使用 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?'

要开始与模型进行交互式聊天,请使用 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!

项目新闻

其他所有内容,请参见我博客上的 llm 标签

目录