From 40d2b884136cdef1c164c01a20773c952f6c2d40 Mon Sep 17 00:00:00 2001 From: LehaoLin Date: Wed, 1 Apr 2026 21:59:54 +0800 Subject: [PATCH 1/2] feat(provider/vllm_rerank): add configurable rerank_api_suffix option Add rerank_api_suffix config option to the VLLM Rerank provider so users can control the API URL path suffix instead of having /v1/rerank hardcoded. - Default value is /v1/rerank (preserves existing behavior) - Users can set it to empty string to disable auto-append - Handles suffix without leading slash by auto-adding one - Schema, default config, and i18n metadata all updated Issue: Fixes #7238 --- astrbot/core/config/default.py | 8 +++++++- astrbot/core/provider/sources/vllm_rerank_source.py | 6 +++++- .../src/i18n/locales/en-US/features/config-metadata.json | 6 +++++- .../src/i18n/locales/zh-CN/features/config-metadata.json | 6 +++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 45412bdccb..1043f6b152 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -1761,6 +1761,7 @@ class ChatProviderTemplate(TypedDict): "enable": True, "rerank_api_key": "", "rerank_api_base": "http://127.0.0.1:8000", + "rerank_api_suffix": "/v1/rerank", "rerank_model": "BAAI/bge-reranker-base", "timeout": 20, }, @@ -1826,7 +1827,12 @@ class ChatProviderTemplate(TypedDict): "rerank_api_base": { "description": "重排序模型 API Base URL", "type": "string", - "hint": "AstrBot 会在请求时在末尾加上 /v1/rerank。", + "hint": "与 rerank_api_suffix 配合使用来确定最终请求路径。", + }, + "rerank_api_suffix": { + "description": "API URL 路径后缀", + "type": "string", + "hint": "追加到 base_url 后的路径,如 /v1/rerank。留空则不追加。", }, "rerank_api_key": { "description": "API Key", diff --git a/astrbot/core/provider/sources/vllm_rerank_source.py b/astrbot/core/provider/sources/vllm_rerank_source.py index edd8a54913..0f3fc64dcf 100644 --- a/astrbot/core/provider/sources/vllm_rerank_source.py +++ b/astrbot/core/provider/sources/vllm_rerank_source.py @@ -20,6 +20,9 @@ def __init__(self, provider_config: dict, provider_settings: dict) -> None: self.auth_key = provider_config.get("rerank_api_key", "") self.base_url = provider_config.get("rerank_api_base", "http://127.0.0.1:8000") self.base_url = self.base_url.rstrip("/") + self.api_suffix = provider_config.get("rerank_api_suffix", "/v1/rerank") + if self.api_suffix and not self.api_suffix.startswith("/"): + self.api_suffix = "/" + self.api_suffix self.timeout = provider_config.get("timeout", 20) self.model = provider_config.get("rerank_model", "BAAI/bge-reranker-base") @@ -45,8 +48,9 @@ async def rerank( if top_n is not None: payload["top_n"] = top_n assert self.client is not None + rerank_url = f"{self.base_url}{self.api_suffix}" async with self.client.post( - f"{self.base_url}/v1/rerank", + rerank_url, json=payload, ) as response: response_data = await response.json() diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index 9ae8672826..dee4f66916 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -1075,7 +1075,11 @@ }, "rerank_api_base": { "description": "Rerank Model API Base URL", - "hint": "AstrBot appends /v1/rerank to the request URL." + "hint": "Combined with rerank_api_suffix to form the full request URL." + }, + "rerank_api_suffix": { + "description": "API URL path suffix", + "hint": "Path appended to base_url, e.g. /v1/rerank. Leave empty to disable auto-append." }, "rerank_api_key": { "description": "API Key", diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index c04138402e..31697cf7c7 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -1077,7 +1077,11 @@ }, "rerank_api_base": { "description": "重排序模型 API Base URL", - "hint": "AstrBot 会在请求时在末尾加上 /v1/rerank。" + "hint": "与 rerank_api_suffix 配合使用来确定最终请求路径。" + }, + "rerank_api_suffix": { + "description": "API URL 路径后缀", + "hint": "追加到 base_url 后的路径后缀,如 /v1/rerank。留空则不追加。" }, "rerank_api_key": { "description": "API Key", From f3575064ee9ec5c22e7c40071812d9d120e86a1f Mon Sep 17 00:00:00 2001 From: LehaoLin Date: Wed, 1 Apr 2026 22:22:55 +0800 Subject: [PATCH 2/2] fix(provider/vllm_rerank): handle null suffix and improve hint descriptions - Add explicit None check for rerank_api_suffix (fixes HIGH from Gemini) - Update rerank_api_base hint to describe actual behavior without mentioning specific provider options (fixes 3x MEDIUM from Gemini) - Add ru-RU i18n for rerank_api_suffix (fixes P2 from Codex) Co-authored-by: gemini-code-assist[bot] Co-authored-by: chatgpt-codex-connector[bot] --- astrbot/core/config/default.py | 2 +- astrbot/core/provider/sources/vllm_rerank_source.py | 2 ++ .../src/i18n/locales/en-US/features/config-metadata.json | 2 +- .../src/i18n/locales/ru-RU/features/config-metadata.json | 6 +++++- .../src/i18n/locales/zh-CN/features/config-metadata.json | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 1043f6b152..7cd4ff6862 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -1827,7 +1827,7 @@ class ChatProviderTemplate(TypedDict): "rerank_api_base": { "description": "重排序模型 API Base URL", "type": "string", - "hint": "与 rerank_api_suffix 配合使用来确定最终请求路径。", + "hint": "最终请求路径由 Base URL 和路径后缀拼接而成(默认为 /v1/rerank)。", }, "rerank_api_suffix": { "description": "API URL 路径后缀", diff --git a/astrbot/core/provider/sources/vllm_rerank_source.py b/astrbot/core/provider/sources/vllm_rerank_source.py index 0f3fc64dcf..e5ed791160 100644 --- a/astrbot/core/provider/sources/vllm_rerank_source.py +++ b/astrbot/core/provider/sources/vllm_rerank_source.py @@ -21,6 +21,8 @@ def __init__(self, provider_config: dict, provider_settings: dict) -> None: self.base_url = provider_config.get("rerank_api_base", "http://127.0.0.1:8000") self.base_url = self.base_url.rstrip("/") self.api_suffix = provider_config.get("rerank_api_suffix", "/v1/rerank") + if self.api_suffix is None: + self.api_suffix = "/v1/rerank" if self.api_suffix and not self.api_suffix.startswith("/"): self.api_suffix = "/" + self.api_suffix self.timeout = provider_config.get("timeout", 20) diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index dee4f66916..92927cebd7 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -1075,7 +1075,7 @@ }, "rerank_api_base": { "description": "Rerank Model API Base URL", - "hint": "Combined with rerank_api_suffix to form the full request URL." + "hint": "The full request URL is formed by combining the Base URL and a path suffix (defaults to /v1/rerank)." }, "rerank_api_suffix": { "description": "API URL path suffix", diff --git a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json index 0aa5c791ac..afb608b4ab 100644 --- a/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json +++ b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json @@ -1076,7 +1076,11 @@ }, "rerank_api_base": { "description": "Base URL API модели Rerank", - "hint": "AstrBot добавляет /v1/rerank к URL запроса." + "hint": "Полный URL запроса формируется путём добавления суффикса к Base URL (по умолчанию /v1/rerank)." + }, + "rerank_api_suffix": { + "description": "Суффикс пути API", + "hint": "Суффикс пути, добавляемый к base_url, например /v1/rerank. Оставьте пустым, чтобы не добавлять." }, "rerank_api_key": { "description": "API Key", diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index 31697cf7c7..8ce6d575f6 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -1077,7 +1077,7 @@ }, "rerank_api_base": { "description": "重排序模型 API Base URL", - "hint": "与 rerank_api_suffix 配合使用来确定最终请求路径。" + "hint": "最终请求路径由 Base URL 和路径后缀拼接而成(默认为 /v1/rerank)。" }, "rerank_api_suffix": { "description": "API URL 路径后缀",