Skip to content

修复Azure渠道对responses API的兼容性支持 - 为Azure渠道添加对responses API的特殊处理 - 兼容微软新… - #1205

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
a37836323:fix-azure-responses-api
Jun 16, 2025
Merged

修复Azure渠道对responses API的兼容性支持 - 为Azure渠道添加对responses API的特殊处理 - 兼容微软新…#1205
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
a37836323:fix-azure-responses-api

Conversation

@a37836323

@a37836323 a37836323 commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

…的API格式,使用preview版本的api-version - 修复了Azure渠道无法正确处理responses请求的问题

Summary by CodeRabbit

  • New Features
    • Added support for handling the "responses" relay mode in the Azure channel, enabling requests to use a dedicated endpoint for this mode.

…的API格式,使用preview版本的api-version - 修复了Azure渠道无法正确处理responses请求的问题
@coderabbitai

coderabbitai Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A special case was added to the GetRequestURL method in the Azure channel adaptor to handle the "responses" relay mode. When this mode is detected, the method returns a fixed request URL for the responses endpoint, bypassing the usual URL construction logic. No public interfaces or error handling mechanisms were altered.

Changes

File(s) Change Summary
relay/channel/openai/adaptor.go Added special case in GetRequestURL to return a fixed URL for "responses" relay mode in Azure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Adaptor
    participant RelayCommon

    Client->>Adaptor: GetRequestURL(info)
    alt info.RelayMode == "responses"
        Adaptor->>RelayCommon: GetFullRequestURL("/openai/v1/responses?api-version=preview")
        RelayCommon-->>Adaptor: Full URL
        Adaptor-->>Client: Return responses endpoint URL
    else
        Adaptor->>Adaptor: Construct URL as usual
        Adaptor-->>Client: Return constructed URL
    end
Loading

Poem

A hop and a skip, a relay anew,
For "responses" mode, we know what to do!
No more guessing, no more roam,
The URL is set—directly home.
Azure paths now neat and bright,
Rabbits code through day and night!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d6859b and 856465a.

📒 Files selected for processing (1)
  • relay/channel/openai/adaptor.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
relay/channel/openai/adaptor.go (1)
relay/constant/relay_mode.go (1)
  • RelayModeResponses (43-43)
🔇 Additional comments (1)
relay/channel/openai/adaptor.go (1)

91-97: Hard-coded preview API version & redundant pre-processing

  1. The string /openai/v1/responses?api-version=preview is hard-coded.
    • If Microsoft ships a non-preview or a new preview version, the adaptor will silently break.
    • Consider extracting the preview tag into a constant (e.g. constant2.AzureResponsesPreviewAPIVersion) or reuse info.ApiVersion when caller sets it explicitly.

  2. The requestURL, task, and model_ scaffolding above is executed unconditionally, then discarded by this early-return. Moving the RelayModeResponses branch to the top of the Azure case (before those computations) avoids pointless work and keeps intent clearer.

 case common.ChannelTypeAzure:
+   // Fast-path for /responses endpoint – no deployment prefix required.
+   if info.RelayMode == constant.RelayModeResponses {
+       apiVersion := info.ApiVersion
+       if apiVersion == "" {
+           apiVersion = constant2.AzureResponsesPreviewAPIVersion // "preview"
+       }
+       requestURL := fmt.Sprintf("/openai/v1/responses?api-version=%s", apiVersion)
+       return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
+   }
+
    apiVersion := info.ApiVersion
    ...
-   // 特殊处理 responses API
-   if info.RelayMode == constant.RelayModeResponses {
-       requestURL = fmt.Sprintf("/openai/v1/responses?api-version=preview")
-       return relaycommon.GetFullRequestURL(info.BaseUrl, requestURL, info.ChannelType), nil
-   }

This refactor keeps behaviour identical while improving maintainability and future-proofing.
[ suggest_optional_refactor ]

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@QuantumNous QuantumNous deleted a comment from coderabbitai Bot Jun 11, 2025
@Calcium-Ion
Calcium-Ion merged commit dc95d0d into QuantumNous:main Jun 16, 2025
@threadshare

Copy link
Copy Markdown

azure 的 responses api 直接配置了带有/v1/responses的地址,好像没有生效,该如何使用呢?或者在配置的时候需要有什么特殊的操作

@a37836323

Copy link
Copy Markdown
Contributor Author

azure 的 responses api 直接配置了带有/v1/responses的地址,好像没有生效,该如何使用呢?或者在配置的时候需要有什么特殊的操作

不需要,正常对接az 渠道,就可以 使用 responses api请求了

@threadshare

Copy link
Copy Markdown

再麻烦问一句,我只看了 merged 的代码。看到是如果 baseUrl 中包含了 /v1/responses 的话会自动拼接完整的 responses api地址。然后我用 responses api 的方式来调用,gpt-4.1 正常返回,但是o3-pro的话显示 “Resource not found”, 实际我使用 curl 自己拼接请求o3-pro的调用是能正常返回的,您知道这可能是什么原因么?

@a37836323

Copy link
Copy Markdown
Contributor Author

可能是什么原因么?
实际我使用 curl 自己拼接请求o3-pro的调用是能正常返回的
你拼接的url 发出来看看呢

@threadshare

Copy link
Copy Markdown

感谢 可能 azure 权限的问题导致 resource 找不到,但是 curl 能调用通,现在可以了。

x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…s-api

修复Azure渠道对responses API的兼容性支持 - 为Azure渠道添加对responses API的特殊处理 - 兼容微软新…
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