Skip to content

[DataProcessor] add strict#7307

Merged
LiqinruiG merged 2 commits intoPaddlePaddle:developfrom
luukunn:add_strict
Apr 14, 2026
Merged

[DataProcessor] add strict#7307
LiqinruiG merged 2 commits intoPaddlePaddle:developfrom
luukunn:add_strict

Conversation

@luukunn
Copy link
Copy Markdown
Collaborator

@luukunn luukunn commented Apr 10, 2026

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

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.

Copilot AI review requested due to automatic review settings April 10, 2026 07:50
@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 10, 2026

Thanks for your contribution!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the OpenAI-compatible protocol schema to support a strict flag on tool/function definitions.

Changes:

  • Add a strict field to FunctionDefinition in the OpenAI protocol models.

name: str
description: Optional[str] = None
parameters: Optional[dict[str, Any]] = None
strict: bool = False
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

这里把 strict 设为 bool = False 会导致在 model_dump()(未设置 exclude_defaults)时,总是把 strict: false 序列化并透传到 engine/request(见 fastdeploy/engine/request.py:293),从而改变未显式指定 strict 的请求负载。为保持与现有行为/文档示例一致(未提供则不发送),建议将其改为 Optional[bool] = None,并在序列化时保持 exclude_none=True 或沿用现有的 value is not None 过滤逻辑。

Suggested change
strict: bool = False
strict: Optional[bool] = None

Copilot uses AI. Check for mistakes.
Comment on lines +224 to +232
name: str
description: Optional[str] = None
parameters: Optional[dict[str, Any]] = None
strict: bool = False
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

PR 描述目前仍是模板内容,缺少最基本的 Motivation / Modifications(为什么要加 strict、解决了什么问题、是否影响兼容性/用法)。建议补充这些信息,并在需要时同步更新相关文档/使用示例说明。

Copilot uses AI. Check for mistakes.
PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7307   +/-   ##
==========================================
  Coverage           ?   74.55%           
==========================================
  Files              ?      383           
  Lines              ?    53589           
  Branches           ?     8405           
==========================================
  Hits               ?    39951           
  Misses             ?    10915           
  Partials           ?     2723           
Flag Coverage Δ
GPU 74.55% <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.

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-13

📋 Review 摘要

PR 概述:为 FunctionDefinition 类添加 strict 字段,支持 OpenAI API 的严格模式功能调用。

变更范围fastdeploy/entrypoints/openai/protocol.py

影响面 Tag[DataProcessor]

📝 PR 规范检查

PR 标题包含有效标签 [DataProcessor],但 PR 描述不完整。MotivationModifications 部分均为空,未说明变更背景和实现细节。

标题建议(可直接复制):

  • 当前:[DataProcessor] add strict(已符合规范)

描述模板(可直接复制):

## Motivation

支持 OpenAI API 中 Function Calling 的严格模式(strict mode),确保模型生成的 JSON 输出严格遵循参数定义的 JSON Schema。参考:https://platform.openai.com/docs/guides/function-calling

## Modifications

在 `FunctionDefinition` 类中添加 `strict: Optional[bool] = None` 字段,与 `JsonSchemaResponseFormat` 的字段定义保持一致。

问题

级别 文件 概述
🟡 建议 protocol.py:232 缺少针对 strict 字段的单元测试

总体评价

代码变更正确且无破坏性风险,strict 字段与 JsonSchemaResponseFormat 保持一致,符合 OpenAI API 规范。建议补充单元测试以验证新字段的序列化/反序列化行为。

name: str
description: Optional[str] = None
parameters: Optional[dict[str, Any]] = None
strict: Optional[bool] = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 虽然变更简单且向后兼容,但建议添加单元测试验证 strict 字段的序列化/反序列化行为,确保与 JsonSchemaResponseFormat.strict 行为一致。

示例测试(可添加到 tests/entrypoints/test_chat.py):

def test_function_strict_field(self):
    """Test strict field in FunctionDefinition"""
    tool = ChatCompletionToolsParam(
        type="function",
        function={
            "name": "get_weather",
            "description": "Get weather info",
            "parameters": {"type": "object", "properties": {}},
            "strict": True,
        }
    )
    self.assertTrue(tool.function.strict)

Copy link
Copy Markdown
Collaborator

@LiqinruiG LiqinruiG left a comment

Choose a reason for hiding this comment

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

LGTM

@LiqinruiG LiqinruiG merged commit 9d9d79c into PaddlePaddle:develop Apr 14, 2026
52 of 56 checks passed
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.

5 participants