feat(openai): support Strict parameter for tool function definitions via ToolInfo.Extra#801
Open
piratf wants to merge 1 commit into
Open
feat(openai): support Strict parameter for tool function definitions via ToolInfo.Extra#801piratf wants to merge 1 commit into
piratf wants to merge 1 commit into
Conversation
Allow setting strict mode on tool functions via ToolInfo.Extra["strict"]. This enables OpenAI Structured Outputs for function calling, ensuring the model generates exact JSON Schema compliant arguments.
Author
|
@JonXSnow @meguminnnnnnnnn Hi team, I saw you have recently been working on this package. Could you please help take a look at this change? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
feat
Check the PR title.
(Optional) Translate the PR title into Chinese.
feat(openai): 通过 ToolInfo.Extra 支持 Tool Function 的 Strict 参数
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Background
OpenAI's Structured Outputs feature supports a
strictparameter on tool function definitions. When set totrue, the model is guaranteed to generate arguments that exactly match the provided JSON Schema — no additional or missing properties, correct types, and valid values.Currently, the internal
functionDefinitionstruct inlibs/acl/openai/tool.golacks aStrictfield, and thetoTools()/genRequest()conversion path completely ignores it. There is no way for users to enable strict mode from business code.Additionally, DeepSeek V4 now supports
stricton tool calls as well, meaning this change benefits both OpenAI and DeepSeek users (when using the OpenAI-compatible endpoint).What this PR does
This is a minimal, backward-compatible change across 3 files:
tool.go: AddStrict boolfield tofunctionDefinitionchat_model.go: ReadstrictfromToolInfo.Extra["strict"]intoTools(), propagate it throughgenRequest()toopenai.FunctionDefinition.Strictchat_model_test.go: AddTestToToolsStrictcovering strict/non-strict/invalid values and fullgenRequestpropagationUsage
Note
After this PR is merged,
components/model/openai/go.modshould be updated to reference the new version oflibs/acl/openai.zh(optional):
背景
OpenAI Structured Outputs 支持在 tool function 定义中设置
strict参数。设为true时,模型保证生成的参数严格匹配 JSON Schema。当前
libs/acl/openai内部的functionDefinition缺少Strict字段,toTools()和genRequest()的转换链路也完全忽略了该参数,业务代码无法启用 strict 模式。此外,DeepSeek V4 现在也支持 tool call 的
strict参数,因此此改动同时惠及通过 OpenAI 兼容接口使用 DeepSeek 的用户。改动说明
最小化、向后兼容的改动,共涉及 3 个文件:
tool.go:functionDefinition增加Strict字段chat_model.go: 从ToolInfo.Extra["strict"]读取 bool 值,经toTools()→genRequest()全链路透传到openai.FunctionDefinition.Strictchat_model_test.go: 新增TestToToolsStrict,覆盖 strict/非 strict/无效值三种场景及genRequest完整传播使用方式
备注
此 PR 合入后,需要更新
components/model/openai/go.mod中对libs/acl/openai的版本引用。(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: