示範一個 RTX 4090 用於訓練 LLM「工具調用(Tool Calling)」的資料格式。這種格式比原本的 Python 範例更接近 OpenAI / Llama / DeepSeek / function calling dataset 常見結構。
我會分成三種常見版本:
1️⃣ 最簡單 instruction-tuning 格式2️⃣ ChatML / 對話式訓練格式
3️⃣ 真正 production 級 tool-calling dataset
1️⃣ 最簡單 Instruction Tuning 格式(最常見)
這是 LoRA / SFT 微調最常見格式。
</>Python
training_data = {
"instruction": "幫我查一下預算表,並在明天下午三點排個審核會。",
"output": """{"tool": "query_database", "params": {"query": "budget_2026"}}
{"tool": "add_calendar_event", "params": {"title": "預算審核", "start_time": "tomorrow 15:00"}}"""
}
優點:
- 結構簡單
- 容易生成大量資料
- 適合 Llama / Qwen / Mistral 微調
缺點:
- 不是真正的多輪對話
- 模型不一定理解工具回傳
2️⃣ ChatML 對話格式 (更接近 ChatGPT)
這是現在很多模型訓練的方式。
</>Python
training_data = {
"messages": [
{
"role": "system",
"content": "你是一位助理,可以使用工具 query_database 和 add_calendar_event。"
},
{
"role": "user",
"content": "幫我查一下預算表,並在明天下午三點排個審核會。"
},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"name": "query_database",
"arguments": {
"query": "budget_2026"
}
},
{
"name": "add_calendar_event",
"arguments": {
"title": "預算審核",
"start_time": "tomorrow 15:00"
}
}
]
}
]
}
這種格式:
- OpenAI function calling
- DeepSeek tool use
- Llama3 tool calling
都很接近。
3️⃣ Production 級 Tool-Calling Dataset(完整流程)
真正好的訓練資料會包含:
1️⃣ 模型呼叫工具
2️⃣ 工具回傳結果
3️⃣ 模型再回答
例如:
</>Python
training_data = {
"messages": [
{
"role": "system",
"content": "你是一位助理,可以使用工具 query_database 和 add_calendar_event。"
},
{
"role": "user",
"content": "幫我查一下預算表。"
},
{
"role": "assistant",
"tool_calls": [
{
"name": "query_database",
"arguments": {
"query": "budget_2026"
}
}
]
},
{
"role": "tool",
"name": "query_database",
"content": "budget_2026.xlsx"
},
{
"role": "assistant",
"content": "我已找到預算表:budget_2026.xlsx"
}
]
}
這種資料能訓練模型:
- 什麼時候呼叫工具
- 如何解析回傳
- 如何繼續回答
4️⃣ 真正大型模型的 Dataset 長相
很多開源工具 dataset 長這樣(JSONL):
{"messages":[...]}
{"messages":[...]}
{"messages":[...]}
例如:
dataset.jsonl
每一行一筆訓練資料。
例如:
{"messages":[{"role":"user","content":"查天氣"},{"role":"assistant","tool_calls":[...]}]}
{"messages":[{"role":"user","content":"查股票"},{"role":"assistant","tool_calls":[...]}]}
5️⃣ 如果你要訓練「武俠小說 AI」
其實可以設計一種 武俠 Tool Calling。
例如:
工具:
1. search_character
2. search_martial_art
3. search_dynasty
資料:
</>Python
{
"instruction":"介紹安祿山",
"output":{
"tool":"search_character",
"params":{"name":"安祿山"}
}
}
模型就會學會:
遇到人物 → 查資料庫
6️⃣ 小模型(RTX4090)訓練建議
如果你用 4090 微調模型
建議:

Dataset量:

✅ 總結
原本 Python 範例:
- 語法 ✔️
- 但不是最佳 dataset 結構
更推薦:
messages
tool_calls
tool response
assistant reply
這是現在 LLM tool training 的主流格式。












