Skip to content

[APIServer]Change the default value of the strict field to False.#7611

Open
luukunn wants to merge 1 commit intoPaddlePaddle:developfrom
luukunn:fix_strict
Open

[APIServer]Change the default value of the strict field to False.#7611
luukunn wants to merge 1 commit intoPaddlePaddle:developfrom
luukunn:fix_strict

Conversation

@luukunn
Copy link
Copy Markdown
Collaborator

@luukunn luukunn commented Apr 24, 2026

Motivation

修改strict字段默认值为False

Modifications

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 24, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-24 17:18:47

📋 Review 摘要

PR 概述:将 FunctionDefinitionstrict 字段的默认值从 Optional[bool] = None 改为 bool = False
变更范围fastdeploy/entrypoints/openai/protocol.py
影响面 TagAPIServer


📝 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,导致以下问题:

  1. 当客户端发送 "strict": null 时,Pydantic 会抛出验证错误(null 无法转换为 bool),请求将失败,破坏现有兼容性
  2. 与同文件 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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@ee81b57). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7611   +/-   ##
==========================================
  Coverage           ?   72.25%           
==========================================
  Files              ?      419           
  Lines              ?    57854           
  Branches           ?     9077           
==========================================
  Hits               ?    41800           
  Misses             ?    13202           
  Partials           ?     2852           
Flag Coverage Δ
GPU 72.25% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants