前言
- https://platform.openai.com/docs/guides/function-calling?api-mode=chat&strict-mode=disabled#additional-configurations
- https://docs.anthropic.com/en/docs/build-with-claude/tool-use/overview#forcing-tool-use
tool_choice
- “none” 就是不用tools, tools傳入也為味空
- auto,就是可能調用tool,或者不調用,agent loop,很多寫的范式都是,調用tool,就執行拿到結果進入下一個loop,如果不調用tool就直接
- required:必須使用其中一個到多個工具,這樣的agentloop可能就是tools里有對應的類似于stopTool,調用到就agent ending
- forced function: 只調用一個特定tool。
claude也是一樣的,就是傳入參數 required 為any了
parallel_tool_calls
parallel_tool_calls = True的時候返回的ChatCompletionMessage中的choice.message.tool_calls有多個 toolcall
為False的時候, 只能每次調用一個tool
Strict mode
“strict”= true的時候更能保證json output的輸出,這個參數感覺大家用的很少,實際上為true和false,對于tool的parameters寫法很多都可以等價
比如:
{"type": "function","function": {"name": "get_weather","description": "Retrieves current weather for the given location.","parameters": {"type": "object","properties": {"location": {"type": "string","description": "City and country e.g. Bogotá, Colombia"},"units": {"type": "string","enum": ["celsius", "fahrenheit"],"description": "Units the temperature will be returned in."}},"required": ["location"],}}
}
這個是我們平時很愛寫的寫法,看到的基本上都是這種,只會把一定需要的參數寫為required中,但openai的"strict"= true, 對type做一下修改是一樣的效果
{"type": "function","function": {"name": "get_weather","description": "Retrieves current weather for the given location.","strict": true,"parameters": {"type": "object","properties": {"location": {"type": "string","description": "City and country e.g. Bogotá, Colombia"},"units": {"type": ["string", "null"],"enum": ["celsius", "fahrenheit"],"description": "Units the temperature will be returned in."}},"required": ["location", "units"],"additionalProperties": false}}
}
加入 "null"的type