欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > 浅谈OpenAIClaude LLM Tools的额外配置

浅谈OpenAIClaude LLM Tools的额外配置

2025/5/13 15:11:38 来源:https://blog.csdn.net/qq_33431368/article/details/147515775  浏览:    关键词:浅谈OpenAIClaude LLM Tools的额外配置

前言

  • 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

  1. “none” 就是不用tools, tools传入也为味空
  2. auto,就是可能调用tool,或者不调用,agent loop,很多写的范式都是,调用tool,就执行拿到结果进入下一个loop,如果不调用tool就直接
  3. required:必须使用其中一个到多个工具,这样的agentloop可能就是tools里有对应的类似于stopTool,调用到就agent ending
  4. 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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词