fix: send input-wrapped payload for qwen3-rerank on native Bailian endpoint (#9360) - #9417
Open
Qixuan112 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Basing the payload branching on
"compatible-api" in self.base_urlcould be brittle if the URL structure changes or additional endpoints are added; consider introducing an explicit flag or endpoint-type enum to make this decision more robust. - The
_make_providerhelper directly instantiatesBailianRerankProvidervia__new__and manually sets attributes, which may drift from the real constructor over time; consider using the actual initializer or a small test-only factory on the provider to keep tests aligned with production usage.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Basing the payload branching on `"compatible-api" in self.base_url` could be brittle if the URL structure changes or additional endpoints are added; consider introducing an explicit flag or endpoint-type enum to make this decision more robust.
- The `_make_provider` helper directly instantiates `BailianRerankProvider` via `__new__` and manually sets attributes, which may drift from the real constructor over time; consider using the actual initializer or a small test-only factory on the provider to keep tests aligned with production usage.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…point (AstrBotDevs#9360) The request body format is determined by the endpoint, not the model. The native DashScope endpoint (/api/v1/services/rerank/...) requires the input-wrapped format and rejects the flat format with HTTP 400, while the compatible-api endpoint requires the flat format. Previously, the code branched on the model name (qwen3-rerank → flat, others → input-wrapped), which produced the wrong payload for: - qwen3-rerank on the native endpoint (flat → 400 error) - non-qwen3 models on the compatible-api endpoint (wrapped → wrong) Additionally, the instruct parameter for qwen3-rerank was never added to parameters for the native endpoint. Branch on endpoint type instead, and apply model-specific constraints (instruct only for qwen3-rerank, return_documents not supported by qwen3-rerank) within each branch. Add unit tests covering all four model × endpoint combinations.
Qixuan112
force-pushed
the
fix/9360-bailian-rerank-native-format
branch
from
July 27, 2026 17:20
a5403b1 to
a87bc6b
Compare
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.
Fixes #9360
Modifications / 改动点
The Bailian rerank adapter previously branched on the model name (
qwen3-rerank→ flat payload, others → input-wrapped), but the request body format is determined by the endpoint, not the model:/api/v1/services/rerank/text-rerank/text-rerank) requires the input-wrapped format ({"input": {...}, "parameters": {...}}) and rejects the flat format with HTTP 400./compatible-api/v1/reranks) requires the flat OpenAI-style format.This caused two bugs:
Additionally, the
instructparameter for qwen3-rerank was never added toparametersfor the native endpoint.Changes:
Refactored
_build_payloadinastrbot/core/provider/sources/bailian_rerank_source.pyto branch on endpoint type first, then apply model-specific constraints (instructonly for qwen3-rerank;return_documentsnot supported by qwen3-rerank) within each branch.Added
tests/test_bailian_rerank_source.pywith unit tests covering all 4 model × endpoint combinations and edge cases.This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Unit tests covering all model × endpoint combinations:
Checklist / 检查清单
Summary by Sourcery
Adjust Bailian rerank payload construction to depend on the endpoint type and add coverage for all model/endpoint combinations.
Bug Fixes:
Tests: