Repository navigation
fix: json_schema 结构化输出按 Chat Completions 规范包装 - #124
Merged
Merged
Conversation
response_format.json_schema 原来直接放裸 schema,DeepInfra、阿里云等严格校验的上游会拒绝请求。现在包装为 {"name":"response","schema":{...}},与 Responses provider 的 text.format 一致;schema 为空时降级为 json_object。GitHub Copilot provider 有同样的实现,一并修复。
Linear: TWI-12
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
概要
Chat Completions 在
ResponseFormat为json_schema时,把 JSON Schema 直接放进response_format.json_schema。按规范,schema 应该放在json_schema.schema下,并带上name。DeepInfra、阿里云等严格校验的上游因此拒绝请求。{"type":"json_schema","json_schema":{"name":"response","schema":{...}}}。name固定为response,与 Responses provider 的text.format一致。strict:Responses 的text.format也没有设置它。打开 strict 会让很多用户 schema 在 OpenAI 官方端点被拒。json_object:修复前这种情况发出的{"type":"json_schema"}本来就缺必填字段,阿里云也会拒绝。text与json_object不变:它们仍只发送type。之前如果json_object上带了 schema,会多发一个无意义的json_schema字段,现在不会了。chatRespFormat实现,存在同样的问题,按同样方式修复。opencode/go复用 completions 包,自动得到修复。docs/providers.md补充了 OpenAI Completions 与 Copilot 的response_format线上格式。关联
验证
response_format的线上 JSON。覆盖未设置、text、json_object、json_schema、schema 为空和 Kimi 兼容模式;completions 同时覆盖 DoGenerate 与 DoStream。go build ./...、go vet ./...、go vet -tags integration ./...、go test ./... -short -count=1 -race、golangci-lint run ./...,全部通过。go mod tidy无变化。deepseek/deepseek-v4.1-flashInput should be 'text'meta-llama/llama-4-scoutInput should be 'text'qwen/qwen3.8-flashNone is not of type 'object', 'boolean'openai/gpt-oss-120b未验证
🤖 Generated with Claude Code