Skip to content

fix: send input-wrapped payload for qwen3-rerank on native Bailian endpoint (#9360) - #9417

Open
Qixuan112 wants to merge 1 commit into
AstrBotDevs:masterfrom
Qixuan112:fix/9360-bailian-rerank-native-format
Open

fix: send input-wrapped payload for qwen3-rerank on native Bailian endpoint (#9360)#9417
Qixuan112 wants to merge 1 commit into
AstrBotDevs:masterfrom
Qixuan112:fix/9360-bailian-rerank-native-format

Conversation

@Qixuan112

@Qixuan112 Qixuan112 commented Jul 27, 2026

Copy link
Copy Markdown

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:

  • The native DashScope endpoint (/api/v1/services/rerank/text-rerank/text-rerank) requires the input-wrapped format ({"input": {...}, "parameters": {...}}) and rejects the flat format with HTTP 400.
  • The compatible-api endpoint (/compatible-api/v1/reranks) requires the flat OpenAI-style format.

This caused two bugs:

  1. qwen3-rerank on the native endpoint sent a flat payload → HTTP 400 (the reported issue).
  2. Non-qwen3 models (e.g. gte-rerank) on the compatible-api endpoint sent an input-wrapped payload → wrong format.

Additionally, the instruct parameter for qwen3-rerank was never added to parameters for the native endpoint.

Changes:

  • Refactored _build_payload in astrbot/core/provider/sources/bailian_rerank_source.py to branch on endpoint type first, then apply model-specific constraints (instruct only for qwen3-rerank; return_documents not supported by qwen3-rerank) within each branch.

  • Added tests/test_bailian_rerank_source.py with 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:

test_qwen3_rerank_native_endpoint_uses_input_wrapped_format
test_qwen3_rerank_native_endpoint_puts_instruct_in_parameters
test_qwen3_rerank_native_endpoint_ignores_return_documents
test_qwen3_rerank_native_endpoint_no_params_when_top_n_zero
test_qwen3_rerank_compatible_endpoint_uses_flat_format
test_qwen3_rerank_compatible_endpoint_ignores_return_documents
test_qwen3_rerank_compatible_endpoint_no_optional_fields
test_gte_rerank_native_endpoint_keeps_input_wrapped_format
test_gte_rerank_native_endpoint_no_instruct
test_gte_rerank_compatible_endpoint_uses_flat_format
test_gte_rerank_compatible_endpoint_no_instruct
test_gte_rerank_compatible_endpoint_no_optional_fields

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 My changes have been well-tested, and verification steps and test results have been provided above.
  • 🤓 I have ensured that no new dependencies are introduced.
  • 😮 My changes do not introduce malicious code.

Summary by Sourcery

Adjust Bailian rerank payload construction to depend on the endpoint type and add coverage for all model/endpoint combinations.

Bug Fixes:

  • Ensure qwen3-rerank uses input-wrapped payloads for the native DashScope endpoint to avoid HTTP 400 errors.
  • Ensure non-qwen3 rerank models use flat OpenAI-style payloads on the compatible-api endpoint instead of input-wrapped requests.
  • Include the instruct parameter for qwen3-rerank in native endpoint requests while ignoring unsupported return_documents options.

Tests:

  • Add unit tests for qwen3-rerank and non-qwen3 models across native and compatible-api endpoints, covering payload structure, parameter handling, and edge cases like zero top_n.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Jul 27, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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
Qixuan112 force-pushed the fix/9360-bailian-rerank-native-format branch from a5403b1 to a87bc6b Compare July 27, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 阿里云百炼 qwen3-rerank 请求格式导致 400 错误,且缺少多模态 Embedding 支持

1 participant