Needle:26M 参数超轻量级工具调用(Function Calling)模型

Needle 是一项模型蒸馏的标志性成果——它将 Google Gemini 的工具调用能力压缩到仅 26M 参数的微型模型中。这意味着开发者可以在资源极度受限的边缘设备上部署高质量的函数调用能力,而无需依赖云端大模型。即使在 E5 + 1030 或单核 800M 内存的 VPS 上也能流畅运行。

项目地址:https://github.com/cactus-compute/needle

安装与快速启动

1. 克隆仓库并安装

git clone https://github.com/cactus-compute/needle.git
cd needle
source ./setup          # 自动创建虚拟环境并安装依赖

2. 启动 Playground(推荐)

needle playground
  • 打开浏览器访问 http://127.0.0.1:7860
  • 首次运行会下载 needle.pkl(约 50MB)的模型文件到项目根目录的 checkpoints/
  • Playground 提供 Web UI,可直接测试工具调用,也支持一键基于你的工具数据微调模型

CLI 使用示例

进入虚拟环境后,可直接使用 needle 命令:

# 激活虚拟环境(如果未自动激活)
source .venv/bin/activate

单次推理(Run)

needle run \
  --checkpoint checkpoints/needle.pkl \
  --query "I want to get a full system overview" \
  --tools "[
        {\"name\":\"mem\",\"description\":\"View Erlang VM memory usage. Returns byte counts for various memory types (total, processes, ETS, binary, etc.).\",\"parameters\":{}},
        {\"name\":\"info\",\"description\":\"View comprehensive Erlang VM runtime information, including node name, scheduler count, process count/limit, ETS count/limit, and detailed memory usage.\",\"parameters\":{}},
        {\"name\":\"top_mem\",\"description\":\"View the top 10 processes with highest memory usage. Returns PID, registered name, initial call, current function, memory, reductions, and message queue length for each.\",\"parameters\":{}},
        {\"name\":\"top_queue\",\"description\":\"View the top 10 processes with longest message queues. Returns PID, registered name, initial call, current function, memory, reductions, and message queue length.\",\"parameters\":{}},
        {\"name\":\"top_reds\",\"description\":\"View the top 10 processes with highest reductions (execution units). Returns PID, registered name, initial call, current function, memory, reductions, and message queue length.\",\"parameters\":{}},
        {\"name\":\"top_bin\",\"description\":\"View the top 10 processes with highest binary memory usage. Returns PID, registered name, initial call, current function, memory, reductions, and message queue length.\",\"parameters\":{}},
        {\"name\":\"ets\",\"description\":\"View ETS table information sorted by memory usage (top 20 tables). Returns table name, memory (in words), and size (number of entries).\",\"parameters\":{}},
        {\"name\":\"mem_detail\",\"description\":\"View detailed Erlang VM memory allocation including allocator states: VM allocated memory, per-type usage, and allocator fragmentation details.\",\"parameters\":{}}
]"

重要提示

  • --query 和 --tools 目前必须使用英文,中文输入可能会导致输出乱码。
  • --tools 参数需传入合法的 JSON 数组字符串(每个工具包含 name、description、parameters)。

示例输出(模型会自动决定调用哪个工具):

<tool_call>[{"name":"info","arguments":{}}]

实际使用注意事项

  • 模型体积小:26M 参数,推理速度极快,适合边缘设备、嵌入式系统、低配服务器。
  • 专精工具调用:在单次函数调用任务上表现优秀,适合构建本地 Agent。
  • 支持微调:通过 Playground 或 needle finetune 命令,使用自己的工具数据集即可快速微调,生成专属模型。
  • 中文支持:当前版本对中文 query 会直接乱码,推荐使用英文提示词以获得最佳效果。

适用场景

  • 低资源设备上的本地 Agent
  • 隐私敏感场景(完全离线运行)
  • 嵌入式系统、智能硬件的工具调用
  • 快速原型验证工具调用逻辑