From 70872cd44bbee114f8c51d8c815757e1edcc4789 Mon Sep 17 00:00:00 2001 From: Rico0919x Date: Sun, 5 Apr 2026 00:15:27 +0800 Subject: [PATCH] feat(provider/vllm_rerank): add configurable rerank_api_suffix option (#7278) * 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 * 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] --------- Co-authored-by: LehaoLin --- astrbot/core/config/default.py | 8 +++++++- astrbot/core/provider/sources/vllm_rerank_source.py | 8 +++++++- .../src/i18n/locales/en-US/features/config-metadata.json | 6 +++++- .../src/i18n/locales/ru-RU/features/config-metadata.json | 6 +++++- .../src/i18n/locales/zh-CN/features/config-metadata.json | 6 +++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 45412bdcc..7cd4ff686 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -1761,6 +1761,7 @@ CONFIG_METADATA_2 = { "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 @@ CONFIG_METADATA_2 = { "rerank_api_base": { "description": "重排序模型 API Base URL", "type": "string", - "hint": "AstrBot 会在请求时在末尾加上 /v1/rerank。", + "hint": "最终请求路径由 Base URL 和路径后缀拼接而成(默认为 /v1/rerank)。", + }, + "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 edd8a5491..e5ed79116 100644 --- a/astrbot/core/provider/sources/vllm_rerank_source.py +++ b/astrbot/core/provider/sources/vllm_rerank_source.py @@ -20,6 +20,11 @@ class VLLMRerankProvider(RerankProvider): 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 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) self.model = provider_config.get("rerank_model", "BAAI/bge-reranker-base") @@ -45,8 +50,9 @@ class VLLMRerankProvider(RerankProvider): 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 9ae867282..92927cebd 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": "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", + "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/ru-RU/features/config-metadata.json b/dashboard/src/i18n/locales/ru-RU/features/config-metadata.json index 0aa5c791a..afb608b4a 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 c04138402..8ce6d575f 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": "最终请求路径由 Base URL 和路径后缀拼接而成(默认为 /v1/rerank)。" + }, + "rerank_api_suffix": { + "description": "API URL 路径后缀", + "hint": "追加到 base_url 后的路径后缀,如 /v1/rerank。留空则不追加。" }, "rerank_api_key": { "description": "API Key",