fix: 使用 removesuffix 替代 rstrip 修复 URL 字符误删问题 (#7026)

之前在 #6863 中我提交的修复使用了 rstrip() 来移除末尾的 /embeddings,
但 rstrip() 是字符集操作,会误删 URL 末尾属于该字符集的字符。

例如 siliconflow.cn 的末尾 n 会被误删,导致 URL 变成 siliconflow.c

改用 removesuffix() 可以正确处理这种情况,只在字符串以指定后缀结尾时才移除。

closes #7025
This commit is contained in:
Izayoi9
2026-03-27 11:24:06 +08:00
committed by GitHub
parent 8986d05309
commit af6f9cfc5e

View File

@@ -27,8 +27,8 @@ class OpenAIEmbeddingProvider(EmbeddingProvider):
api_base = (
provider_config.get("embedding_api_base", "https://api.openai.com/v1")
.strip()
.rstrip("/")
.rstrip("/embeddings")
.removesuffix("/")
.removesuffix("/embeddings")
)
if api_base and not api_base.endswith("/v1") and not api_base.endswith("/v4"):
# /v4 see #5699