[APIServer]Change the default value of the strict field to False.#7611
[APIServer]Change the default value of the strict field to False.#7611luukunn wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-24 17:18:47
📋 Review 摘要
PR 概述:将 FunctionDefinition 中 strict 字段的默认值从 Optional[bool] = None 改为 bool = False
变更范围:fastdeploy/entrypoints/openai/protocol.py
影响面 Tag:APIServer
📝 PR 规范检查
Modifications 章节未填写:PR 描述中 Modifications 部分为空,需要补充说明本次变更的具体内容和影响。
标题建议(可直接复制):
[APIServer] Change the default value of the strict field to False
(原标题 [APIServer]Change... 缺少 Tag 与描述之间的空格,以及描述末尾不需要句号)
Modifications 建议(可直接复制):
## Modifications
将 `FunctionDefinition.strict` 字段类型从 `Optional[bool] = None` 改为 `bool = False`,
确保在客户端未传递 strict 字段时,默认值为 False 而非 None,避免下游逻辑处理 None 值。
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 兼容性 | protocol.py:233 |
类型从 Optional[bool] 改为 bool,导致传入 null 时 Pydantic 验证失败 |
| ❓ 疑问 | protocol.py:466 |
同文件 JsonSchemaResponseFormat.strict 仍为 Optional[bool] = None,两处不一致 |
🔴 兼容性问题:破坏 OpenAI API 规范兼容性
变更前:strict: Optional[bool] = None
变更后:strict: bool = False
问题:OpenAI 官方 API 规范 中,FunctionDefinition.strict 的类型为 boolean or null,即客户端可以合法地传递 "strict": null。本次变更将类型从 Optional[bool] 改为 bool,导致以下问题:
- 当客户端发送
"strict": null时,Pydantic 会抛出验证错误(null无法转换为bool),请求将失败,破坏现有兼容性。 - 与同文件
JsonSchemaResponseFormat.strict: Optional[bool] = None(第 466 行)的处理方式不一致。
建议修复:保留 Optional[bool],仅修改默认值:
# 修改前
strict: Optional[bool] = None
# 建议修改为(兼容 null 传入,同时提供 False 作为默认值)
strict: Optional[bool] = False这样既满足"默认值为 False"的需求,也不会拒绝传入 null 的合法请求。
❓ 疑问:同文件另一处 strict 字段是否需要同步修改?
JsonSchemaResponseFormat(第 466 行)同样有 strict: Optional[bool] = None,与本次修改后的 FunctionDefinition.strict 不一致。请确认是否需要统一处理?
总体评价
变更目标合理(为 strict 提供明确默认值),但直接将类型从 Optional[bool] 改为 bool 会导致 Pydantic 拒绝 null 输入,破坏 OpenAI API 兼容性。建议改为 Optional[bool] = False 以同时满足两个目标。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7611 +/- ##
==========================================
Coverage ? 72.25%
==========================================
Files ? 419
Lines ? 57854
Branches ? 9077
==========================================
Hits ? 41800
Misses ? 13202
Partials ? 2852
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
修改strict字段默认值为False
Modifications
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.