Skip to content

让 /v1/responses 文本请求按 Grok 模型路由到 Console#17

Merged
zqbxdev merged 8 commits into
zqbxdev:devfrom
Zker67:fix-grok-responses-routing
May 25, 2026
Merged

让 /v1/responses 文本请求按 Grok 模型路由到 Console#17
zqbxdev merged 8 commits into
zqbxdev:devfrom
Zker67:fix-grok-responses-routing

Conversation

@Zker67
Copy link
Copy Markdown
Contributor

@Zker67 Zker67 commented May 24, 2026

变更说明

这个 PR 处理 #11/v1/responses 文本请求使用 Grok 模型时,不再静默进入通用文本后端,而是按模型 provider 显式路由。

主要改动

  • /v1/responses 文本路径增加模型解析:

    • Grok Console 模型路由到现有 grok.console_chat_completion()
    • Grok app-chat 模型在 /v1/responses 返回明确 501,避免静默走错后端。
    • 非 Grok 文本请求保持原有通用文本后端路径。
  • Responses 输出保持现有事件结构:

    • 非流式返回 response.completed 中的 Responses 格式对象。
    • stream=true 返回 response.createdresponse.output_text.deltaresponse.output_text.doneresponse.completed 等兼容事件。
  • build_console_payload() 保留 Responses 工具字段:

    • tools
    • tool_choice
    • parallel_tool_calls

验证

已通过定向回归测试:

uv run python -m unittest \
  test.test_grok_provider.GrokProviderTests.test_build_console_payload_preserves_response_tools \
  test.test_grok_provider.GrokProviderTests.test_responses_grok_console_routes_to_console_completion \
  test.test_grok_provider.GrokProviderTests.test_streaming_responses_grok_console_emits_response_events \
  test.test_grok_provider.GrokProviderTests.test_responses_grok_app_chat_returns_explicit_error

结果:Ran 4 tests ... OK

另外执行了:

git diff --check

结果:通过。

说明:python -m unittest test.test_grok_provider 仍存在一个既有测试替身错误,curl_cffi.requests.Session=object 导致 object(**kwargs) 报错,和本 PR 修改的 Responses 路由无关。

关联:#11

Copy link
Copy Markdown

@github-actions github-actions 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 PR Review

Decision: comment
Confidence: 0.79

Summary

整体改动方向正确,已将 /v1/responses 文本请求按模型 provider 分流到 Grok Console,并为 Grok app-chat 返回显式 501,且补充了覆盖核心路径的测试。未发现明确阻塞合并的问题。

Findings

  1. [info] services/protocol/openai_v1_response.py:214 - 当前 response_events() 在文本请求路径会先 resolve_model(model) 再决定是否走 Grok 路由;这意味着即使是非 Grok 文本模型,也会新增一次模型解析流程。建议确认这不会改变既有“未知/别名模型”在通用文本后端的容错行为(例如以前可透传、现在可能提前失败)。

Recent Comment Summary

实现与 PR 目标一致,测试补充也较完整;建议额外确认一次对非 Grok/未知模型的兼容行为,避免引入非预期回归。

@Zker67
Copy link
Copy Markdown
Contributor Author

Zker67 commented May 24, 2026

补充说明:当前 enforce 检查失败不是代码或目标分支问题。这个 PR 的 base 是 dev。失败日志显示 workflow 在执行 removeWrongTargetBranchLabel() 时调用 DELETE /issues/17/labels/wrong-target-branch,但 fork PR 场景下 GITHUB_TOKEN 对该 label 操作返回 403 Resource not accessible by integration。\n\nreview 检查已通过;本地定向回归测试也已通过。

Zker67 and others added 7 commits May 25, 2026 12:29
Default routine Docker publish builds to linux/amd64, keep tag releases multi-platform, and validate manual platform inputs.
Adds the default Grok Console web_search tool while preserving caller-supplied web_search/x_search tools.
Routes Grok app-chat direct REST requests first unless a Browser Bridge URL is explicitly configured, while preserving bridge fallback for selected upstream failures.
Copy link
Copy Markdown

@github-actions github-actions 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 PR Review

Decision: comment
Confidence: 0.84

Summary

整体改动与 PR 目标(/v1/responses 对 Grok 模型显式路由)一致,测试覆盖也明显增强。未在已提供补丁中发现明确会导致功能错误的阻断性问题。

Findings

  1. [info] services/protocol/openai_v1_response.py:152 - stream_grok_console_response()stream=true 场景下仍调用一次性 grok.console_chat_completion(),当前会以单次 response.output_text.delta 输出完整文本而非真正逐段上游流式转发。该实现与现有事件结构兼容,但如果目标是降低首包延迟/实现真实 token 流,可后续考虑切到 console_chat_completion_events()
  2. [info] .github/workflows/docker-publish.yml:4 - 发布工作流新增了 push.branches: [main] 触发条件。鉴于仓库开发分支为 devmain 为稳定分支,这一配置在发布策略上是可理解的;建议团队确认是否希望在 main 的每次 push 也触发镜像发布(而不仅是 tag 发布),以避免非预期发布频率。

Recent Comment Summary

实现方向正确、测试补充充分;建议仅就“responses 流式是否需要真实上游流转发”与“main push 触发发布策略”做产品/运维层确认。

@zqbxdev zqbxdev merged commit 9463c3b into zqbxdev:dev May 25, 2026
1 of 2 checks passed
@zqbxdev
Copy link
Copy Markdown
Owner

zqbxdev commented May 25, 2026

感谢贡献,PR #17 已完成审查并 squash merge 到 dev。

合并信息:

本次合并前处理:

  • 将 PR branch rebase/merge 到当前 dev,解决与已合并 Grok Console streaming/search-tool 测试的冲突。
  • 保留现有 Grok Console search tool 过滤逻辑;只新增透传 tool_choice / parallel_tool_calls。
  • 增加未知非 Grok model 仍走通用 text backend 的回归测试。

合并验证:

  • GitHub review check: passed
  • focused Grok Responses tests: Ran 7 tests ... OK
  • adjacent Grok/Bridge regressions: Ran 19 tests ... OK
  • compileall for changed Python files: passed
  • Docker build/smoke: passed,/health 返回 {"status":"ok"},/version 返回 {"version":"0.0.7"}

说明:

  • PR 页面上的 enforce 失败来自该 PR 运行时使用的旧 workflow,对 fork PR 的 wrong-target-branch label cleanup 返回 403;当前 dev 的 workflow 已捕获该 403,后续同步运行不应再因这个 cleanup 步骤 false-red。
  • 合并后另外做了本地测试维护:让缺少 requests 时的 test.test_v1_responses 正常 skip,并修正一个已过期的 Grok image unsupported 测试用例;本地现在 python3 -m unittest test.test_v1_responses test.test_grok_provider 为 Ran 77 tests ... OK (skipped=6)。

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.

2 participants