修复聊天请求参数校验与错误状态码 - #2
Merged
Merged
Conversation
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.
本次由 Codex 协助实现并验证,修复来自用户提供的线上复现:
max_tokens: -1被错误返回为 500,temperature: 10在 GPT-5 适配前未被拒绝。📝 变更描述 / Description
请求解析或参数校验失败时,控制器现在返回 HTTP 400 并停止重试;客户端只收到
invalid request,不再得到 Go 结构体和解析细节。保留已有的大请求体 413 响应。OpenAI 兼容聊天请求会在模型适配前校验
temperature。未提供参数、0 和 2 保持有效,低于 0、超过 2、NaN 和无穷值会被拒绝。这样 GPT-5 适配器删除不支持字段前,非法值已经返回 400。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
用户报告的线上请求参数校验问题,无独立 Issue。
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
go test ./relay/helper -run TestMaxTokensBounds -count=1通过。go test ./controller -run TestRelayInvalidRequestReturnsBadRequestBeforeUpstream -count=1通过。go test ./relay/channel/openai -count=1通过。控制器回归测试验证
max_tokens: -1和temperature: 10都返回 400、包含invalid_request,且响应不泄露GeneralOpenAIRequest。该路径在生成渠道和预扣费信息之前返回,因而不会调用上游。风险:仅对 OpenAI 兼容文本请求的 temperature 应用 OpenAI 范围
[0, 2],未改变其它协议或模型适配器对合法参数的兼容行为。