跳到主要内容

微调deepseek-r1蒸馏版工具调用

· 阅读需 6 分钟
Danny He
Developer in ChengDu,China

有关deepseek-r1蒸馏版的微调方案,目前主流在用<think></think>的形式组织相关语料样本,目前还未涉及到工具调用(Function-Call)的形式, 刚好同事需要基于LLaMA-Factory构建思维链的工具调用语料,于是我顺便补充了一下LLaMA-Factory关于chat template的单元测试,以推导出LLaMA-Factory中关于样本集处理以及抛开JSON格式理解本质chat template。 思维不要固化。

http://localhost:3000
[
{
"conversations": [
{
"value": "Hi, can you tell me the current stock price of Apple?",
"from": "human"
},
{
"value": "<think>Alright, the user asked for the current stock price of Apple. Looking at the tools available, there's a function called get_stock_price which exactly fits this request. I'll need to call this function with the parameter company set to 'Apple' to retrieve the information the user is asking for. This seems like the most straightforward and appropriate action to take.\n</think><tool_call>\n{'name': 'get_stock_price', 'arguments': {'company': 'Apple'}}\n</tool_call>",
"from": "gpt"
},
{
"value": "<tool_response>\n{'stock_price': '$150.75'}\n</tool_response>",
"from": "human"
},
{
"value": "The current stock price of Apple is $150.75.",
"from": "gpt"
},
{
"value": "That's great. Can you also tell me the stock price for Microsoft?",
"from": "human"
},
{
"value": "<think>Alright, let me try to figure out how to handle this user's request. The user first asked about Apple's stock price, and I responded by calling the get_stock_price function with 'Apple' as the argument. The tool provided the price, and I passed that information back to the user.\n\nNow, the user is asking for the stock price of Microsoft. I need to determine the appropriate action here. Looking at the tools available, there's still the get_stock_price function, which is designed to fetch current stock prices. Since the user is requesting another company's stock price, it makes sense to use the same function again but with the company name changed to Microsoft. \n\nI shouldn't assume any other tools are needed because the available functions are specifically tailored for stock prices and movie details. In this case, the relevant function is get_stock_price. I should ensure that the function is called with the correct parameter, 'Microsoft' in this case, to retrieve the accurate information the user is seeking. This approach is efficient and aligns directly with the user's request without making unnecessary assumptions or using unrelated tools.\n</think><tool_call>\n{'name': 'get_stock_price', 'arguments': {'company': 'Microsoft'}}\n</tool_call>",
"from": "gpt"
},
{
"value": "<tool_response>\n{'stock_price': '$210.22'}\n</tool_response>",
"from": "human"
},
{
"value": "The current stock price of Microsoft is $210.22.",
"from": "gpt"
},
{
"value": "Thank you for the information.",
"from": "human"
},
{
"value": "You're welcome! If you have any other questions, feel free to ask.",
"from": "gpt"
}
],
"system": "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions.Here are the available tools:<tools> [{'type': 'function', 'function': {'name': 'get_stock_price', 'description': 'Get the current stock price of a company', 'parameters': {'type': 'object', 'properties': {'company': {'type': 'string', 'description': 'The name of the company'}}, 'required': ['company']}}}, {'type': 'function', 'function': {'name': 'get_movie_details', 'description': 'Get details about a movie', 'parameters': {'type': 'object', 'properties': {'title': {'type': 'string', 'description': 'The title of the movie'}}, 'required': ['title']}}}] </tools>Use the following pydantic model json schema for each tool call you will make: {'title': 'FunctionCall', 'type': 'object', 'properties': {'arguments': {'title': 'Arguments', 'type': 'object'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['arguments', 'name']}For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n<tool_call>\n{tool_call}\n</tool_call>",
}
]