<|end▁of▁thinking|>🍎 apfel:5.3k Stars,把 Mac 自带的 AI 当 CLI 用,零 API 费用
项目地址:github.com/Arthur-Ficial/apfel | ⭐ 5,324 Stars | 🛠 Swift | macOS 26+
老实说,Mac 用户可能都不知道自己电脑里已经装了个 LLM——Apple 从 macOS 26 开始在系统里内置了 FoundationModels 框架,但一直没给个命令行界面。
apfel 就是干这个的。一个 Swift 写的 CLI 工具,把 Apple 芯片上的本地模型暴露成 UNIX 管道和 OpenAI 兼容 API。100% 本地运行,不需要 API Key,不需要联网,甚至不需要装 Xcode。
一句话安装
brew install apfel
或者从源码编译(只要命令行工具,不需要 Xcode):
git clone https://github.com/Arthur-Ficial/apfel.git && cd apfel && make install
日常怎么用
最骚的操作是当管道用——跟 Unix 哲学完美融合:
# 直接问
apfel "What is the capital of Austria?"
# 管道输入
echo "Summarize: $(cat README.md)" | apfel
# 附加上下文文件
apfel -f old.swift -f new.swift "What changed between these two files?"
# JSON 输出,配合 jq 食用
apfel -o json "Translate to German: hello" | jq .content
# 安静模式,适合脚本调用
result=$(apfel -q "Capital of France? One word.")
当本地 API 服务器用
一行命令拉起 OpenAI 兼容的 API 服务,后面可以直接对接任何 OpenAI SDK:
apfel --serve # 前台运行
brew services start apfel # 后台常驻(跟 Ollama 一样)
然后就能用标准 OpenAI 客户端调用了:
curl http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"apple-foundationmodel","messages":[{"role":"user","content":"Hello"}]}'
Python 调用也一样:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="unused")
resp = client.chat.completions.create(
model="apple-foundationmodel",
messages=[{"role": "user", "content": "What is 1+1?"}],
)
print(resp.choices[0].message.content)
几个实用 demo
项目自带了几个好玩的 shell 脚本:
# 自然语言转 shell 命令
demo/cmd "find all .log files modified today"
# → find . -name "*.log" -type f -mtime -1
demo/cmd -x "what process is using port 3000" # -x = 确认后执行
# 英文描述 -> 复杂管道命令
demo/oneliner "sum the third column of a CSV"
# → awk -F',' '{sum += $3} END {print sum}' file.csv
也可以加到 .zshrc 里当全局命令用——日常查端口、总结 git 活动、解释报错信息,都一句话搞定。
限制要说清楚
总结
brew install apfel 一键安装,零配置cmd / oneliner 等 demo 脚本即装即用适合的场景:日常脚本里加点 AI 能力、写个自动化小工具但又不想买 API 额度、或纯本地隐私优先的场景。不是要取代 ChatGPT/Claude,而是在"够用就行"的地方提供一个零成本的选项。