simonw/llm · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈
LLM
一个用于与 OpenAI、Anthropic’s Claude、Google’s Gemini、Qwen、Gemma、Kimi、DeepSeek、Mistral 以及数十种其他大型语言模型进行交互的 CLI 工具和 Python 库,既支持通过远程 API,也支持在本地机器上安装和运行的模型。
在 YouTube 上观看 Language models on the command-line 以查看演示,或阅读配套详细笔记。
使用 LLM,你可以:
- 从命令行运行提示词
- 将提示词和响应存储在 SQLite 中
- 生成并存储嵌入向量
- 从文本和图像中提取结构化内容
- 授予模型执行工具的能力
- … 以及更多、更多的功能
快速开始
首先,使用 pip 或 Homebrew 或 pipx 或 uv 安装 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"
使用各自的插件,针对 Gemini 或 Anthropic 运行提示词:
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!
项目新闻
- 2026年4月29日:LLM 0.32a0 是一次重大的向后兼容重构
- 2025年8月11日:LLM 0.27,带注释的发布说明:GPT-5 和改进的工具调用
- 2025年5月27日:大型语言模型现在可以通过 LLM 0.26 在你的终端中运行工具
- 2025年5月5日:在 CLI 上将视频作为 JPEG 帧序列输入视觉 LLM(也是 LLM 0.25)
- 2025年4月7日:LLM 0.24 使用片段和模板插件支持长上下文
- 2025年2月28日:使用 LLM 模式从非结构化内容中提取结构化数据
- 2025年2月17日:LLM 0.22,带注释的发布说明
- 2024年10月29日:你现在可以使用 LLM 在终端中对图像、音频和视频运行提示词
- 2024年1月26日:LLM 0.13:带注释的发布说明
- 2023年9月12日:使用 llm-clip 构建图像搜索引擎,使用 llm chat 与模型聊天
- 2023年9月4日:LLM 现在提供用于处理嵌入的工具
- 2023年7月12日:LLM CLI 工具现在通过插件支持自托管语言模型
- 2023年5月18日:llm、ttok 和 strip-tags——用于处理 ChatGPT 和其他 LLM 的 CLI 工具
- 2023年4月4日:llm CLI 工具的原始公告
其他所有内容,请参见我博客上的 llm 标签。