介绍通过 LLM CLI 工具和 replicate 插件从终端便捷调用 Llama 2 的方法。
今天的重磅新闻是 Llama 2,这是来自 Meta AI 的新型开源许可大语言模型。这是一件真正的大事:
Llama 2 可免费用于研究和商业用途。
(swyy 发现它在几小时前从 LLaMA 2 更名为 Llama 2。)
Facebook 在二月份发布的原始 LLaMA 模型,在开源 LLM 世界中引发了一波地震式的创新浪潮——从微调变体到从零开始的重构。我在其原始发布后的几周写过关于这一影响的文章《大语言模型正在经历它们的 Stable Diffusion 时刻》。如果说什么的话,我低估了这会有多么重大的意义。
但有一个问题:你不能将其用于商业目的。
这在 Llama 2 上改变了!
不过它仍然有一些有趣的限制,我强调一下:
你不得使用 Llama 相关材料或任何输出或 Llama 相关材料的结果来改进任何其他大语言模型(除 Llama 2 或其衍生作品外)。
如果在 Llama 2 版本发布日期,被许可人或其关联方提供的产品或服务的月活跃用户数超过前一个日历月的 7 亿月活跃用户,你必须向 Meta 请求许可证,Meta 可以按其绝对判断权向你授予该许可证[...]
这仍然使其可用于大多数商业目的。让我们试试吧。
我的 LLM 工具提供了对各种语言模型的命令行访问,既可以通过 web API,也可以自托管在你自己的机器上。
上周我添加了插件支持来扩展它以支持新模型。一个独立发布的插件现在可以为现有的 CLI 工具添加对新模型的支持。
全新的 llm-replicate 插件提供对 Replicate 托管的模型的 CLI 访问,今天早上 a16z-infra 发布了 a16z-infra/llama13b-v2-chat,提供对新 Llama 2 13B chat 模型的 Replicate API 访问。
你需要一个 Replicate API 密钥。
像这样安装 LLM:
pip install llm
(我喜欢使用 pipx。)
或者如果你没有设置 pip 但可以使用 Homebrew:
brew install simonw/llm/llm
运行 llm --version 确认它已安装。
接下来,安装 llm-replicate 插件:
llm install llm-replicate
该插件添加了一个新的 llm replicate 命令集——用 llm --help 查看它们。
配置你的 Replicate API 密钥,以便插件可以与 API 通信:
llm keys set replicate
Enter key: <paste key here>
用插件注册新的 a16z-infra/llama13b-v2-chat 模型:
llm replicate add a16z-infra/llama13b-v2-chat \
--chat --alias llama2
这告诉插件它是一个 "chat" 模型,这意味着你可以与它进行持续的对话,而不仅仅是发送单个提示。
现在我们可以使用我们配置的 llama2 别名发送提示:
llm -m llama2 "Ten great names for a pet pelican"
当然!以下是十个很好的宠物鹈鹕名字:
Peanut: A cute and playful name for a small pelican.
Puddles: A fun and silly name for a pelican that loves to splash around in water.
Pete: A classic name that suits a friendly and outgoing pelican.
Penelope: A pretty and elegant name for a female pelican.
Percy: A charming and sophisticated name for a male pelican.
Pippy: A playful and affectionate name for a pelican with a lively personality.
Pelty: A fun and quirky name for a pelican with a unique sense of style.
Pip: A sweet and endearing name for a small pelican.
Plucky: A feisty and adventurous name for a pelican with a big personality.
Poppy: A lovely and delicate name for a female pelican with a sweet disposition.
我希望这些建议能帮助你为你的宠物鹈鹕找到完美的名字!
因为它是一个 chat 模型,我们可以向同一个对话发送后续提示:
llm -c "Five more and make them more nautical"
Ahoy! Here be five more nautical names for yer pet pelican:
Seabird: A fitting name for a pelican that loves the ocean and all its wonders.
Captain Hook: A swashbuckling name for a pelican with a bold and fearless spirit.
Anchor: A sturdy and dependable name for a pelican that's always grounded and stable.
Finley: A fishy name for a pelican with a love for the sea and all its creatures.
Buoyant: A bouncy and cheerful name for a pelican with a lighthearted and carefree attitude.
Hope these suggestions float yer boat, matey!
LLM 将通过它发送的每个提示和响应记录到 SQLite 数据库中。我这里使用 --truncate 来缩短输出以包含在这篇文章中:
llm logs --truncate
[
{
"id": "01h5n5b3q6s54e03wtvqe90w2g",
"model": "replicate-a16z-infra-llama13b-v2-chat",
"prompt": "Five more and make them more nautical",
"system": null,
"response": "Ahoy matey! Here be five more nautical-themed names for yer pet pelican:\n\n1. Captain Hook\n2. Anch...",
"response_json": null,
"conversation_id": "01h5n5atsqfg4bhxc53j3ymnx2",
"duration_ms": 7364,
"datetime_utc": "2023-07-18T18:48:51.999944",
"conversation_name": "Ten great names for a pet pelic\u2026",
"conversation_model": "replicate-a16z-infra-llama13b-v2-chat"
},
{
"id": "01h5n5atss6k9zsr5qs5hb2wzd",
"model": "replicate-a16z-infra-llama13b-v2-chat",
"prompt": "Ten great names for a pet pelican",
"system": null,
"response": "Sure, here are ten great names for a pet pelican:\n\n1. Pelty\n2. Peanut\n3. Puddles\n4. Nibbles\n5. Fu...",
"response_json": null,
"conversation_id": "01h5n5atsqfg4bhxc53j3ymnx2",
"duration_ms": 7873,
"datetime_utc": "2023-07-18T18:48:42.356413",
"conversation_name": "Ten great names for a pet pelic\u2026",
"conversation_model": "replicate-a16z-infra-llama13b-v2-chat"
}
]
或运行 llm logs path 查看 SQLite 数据库文件的路径。如果你安装了 Datasette,你可以像这样打开日志数据库:
datasette "$(llm logs path)"
或使用 Datasette Desktop:
open "$(llm logs path)"
我对 Llama 2 真的很兴奋。我期待我们将开始看到各种创新建立在它之上,因为模型权重本身开始推出。
我特别期待:
微调模型。Alpaca、Vicuna 等在原始 LLaMA 上的微调做了了不起的事情。我预计我们在接下来的几周内会看到几十个微调模型。
reAct 和 Toolformer 模式的实现,这将使 Llama 2 能够以类似于 OpenAI Functions 的方式驱动外部工具。Llama 2 论文已经提到对 Toolformer 提示的测试,所以希望这不会太困难。
希望这一次我们将开始看到人们的一致努力,为 Llama 2 记录哪些类型的提示在实际目的中效果良好,因为我预计这个模型在未来一段时间内将是生态系统的一个有影响力的部分。
OpenAI 对 Hugging Face 的意外网络攻击是发生了的科幻小说 - 2026 年 7 月 22 日
与 Claude Code 团队的 Cat 和 Thariq 的炉边谈话 - 2026 年 7 月 21 日
Kimi K3 以及我们仍然可以从鹈鹕基准中学到什么 - 2026 年 7 月 16 日
这是 Simon Willison 发布的《使用 llm-replicate 插件从命令行访问 Llama 2》,发布于 2023 年 7 月 18 日。
下一篇:sqlite-utils 现在支持插件
上一篇:周记:使用 LLM 插件的自托管语言模型、新的 Datasette 教程、十几个包发布、十几个 TIL
以每月 $10 的价格赞助我,获取本月最重要 LLM 发展的精选电子邮件摘要。
付钱让我少给你发送!