Views
No views yet
| 指标 | 训练前 base(0.6B) | 本模型(蒸馏后) | 教师(8B) |
|---|---|---|---|
| 工具调用精确匹配(名+参) | 59.0% | 94.3% | 97.8% |
| 工具选择准确率 | 79.4% | 94.9% | 98.3% |
| 参数 schema 合规率 | 96.6% | 99.4% | 100% |
| 越界请求·正确拒调用 | 98.1% | 100% | 100% |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "yifan02/qwen3-0.6b-tool-distill"
4tok = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(model_id, dtype="bfloat16").cuda()
6
7tools = [{"type": "function", "function": {
8 "name": "set_volume",
9 "description": "设置指定音频设备的音量大小(0-100)。",
10 "parameters": {"type": "object", "properties": {
11 "device": {"type": "string", "enum": ["living_room","bedroom","kitchen","study","all"]},
12 "level": {"type": "integer", "minimum": 0, "maximum": 100}},
13 "required": ["device","level"]}}}] # 完整 7 个工具见 GitHub 仓库
14
15msgs = [{"role":"system","content":"你是一个智能音频助手,负责控制家里的音频设备。"},
16 {"role":"user","content":"把客厅音量调到40"}]
17text = tok.apply_chat_template(msgs, tools=tools, add_generation_prompt=True, tokenize=False)
18out = model.generate(**tok(text, return_tensors="pt").to("cuda"), max_new_tokens=512)
19print(tok.decode(out[0], skip_special_tokens=True))
20# -> <think>...</think> <tool_call>{"name":"set_volume","arguments":{"device":"living_room","level":40}}</tool_call>