From 4d2791aa9acaf167ebedd9e0216a93428f5e3f53 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Wed, 1 Apr 2026 11:55:54 +0800 Subject: [PATCH] fix: support both old and new Bailian Rerank API response formats (#7217) * fix: support both old and new Bailian Rerank API response formats The new compatible API (compatible-api/v1/reranks) returns results at the top level as data.results, while the old API returns them nested under data.output.results. The parser only checked the old path, causing qwen3-rerank to always report empty results. Fixes #7161 * Update astrbot/core/provider/sources/bailian_rerank_source.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Ruochen Pan Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- astrbot/core/provider/sources/bailian_rerank_source.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/astrbot/core/provider/sources/bailian_rerank_source.py b/astrbot/core/provider/sources/bailian_rerank_source.py index a515d2b9d..4513c2c85 100644 --- a/astrbot/core/provider/sources/bailian_rerank_source.py +++ b/astrbot/core/provider/sources/bailian_rerank_source.py @@ -142,7 +142,8 @@ class BailianRerankProvider(RerankProvider): f"百炼 API 错误: {data.get('code')} – {data.get('message', '')}" ) - results = data.get("output", {}).get("results", []) + # 兼容旧版 API (output.results) 和新版 compatible API (results) + results = (data.get("output") or {}).get("results") or data.get("results") or [] if not results: logger.warning(f"百炼 Rerank 返回空结果: {data}") return []