AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

fix: rstrip() 误删 URL 末尾字符导致 embedding API 连接失败

Open Izayoi9 opened this issue 8 months ago • 1 comments

What happened / 发生了什么

在使用 OpenAI Embedding Provider 时,如果 API Base URL 以 /embeddings 字符集中的字符结尾(如 siliconflow.cn 的 n),会被 rstrip() 误删导致 URL 错误。

例如:

  • 输入:https://api.siliconflow.cn
  • 实际结果:https://api.siliconflow.c/v1(n 被误删)
  • 期望结果:https://api.siliconflow.cn/v1

Reproduce / 如何复现?

  1. 添加一个 OpenAI Embedding 类型的提供商
  2. 设置 API Base URL 为 https://api.siliconflow.cn
  3. 保存并重启 AstrBot
  4. 查看日志,显示的 URL 为 https://api.siliconflow.c/v1(n 被误删)

AstrBot version, deployment method / AstrBot 版本、部署方式

v4.22.1 Docker

OS

Linux

Logs / 报错日志

[OpenAI Embedding] 硅基流动qwen3 8B Using API Base: https://api.siliconflow.c/v1

注意 URL 中的 siliconflow.c 应该是 siliconflow.cn,n 被 rstrip("/embeddings") 误删了。

原因分析

之前的 PR #6863 中使用了 .rstrip("/embeddings") 来移除末尾的 /embeddings 路径。

但 rstrip() 是字符集操作,会移除末尾所有在指定字符串中的字符,而不是移除子字符串。

# 错误用法
"siliconflow.cn".rstrip("/embeddings")  # 结果: "siliconflow.c"(n 被删掉了)

# 正确用法
"siliconflow.cn".removesuffix("/embeddings")  # 结果: "siliconflow.cn"(无变化)

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [x] Yes!

Code of Conduct

  • [x] I have read and agree to abide by the project's Code of Conduct.

Izayoi9 avatar Mar 26 '26 18:03 Izayoi9

自己拉的史自己修(1/1)

Izayoi9 avatar Mar 26 '26 18:03 Izayoi9