Skip to content

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

@Izayoi9

Description

@Izayoi9

What happened / 发生了什么

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

例如:

  • 输入:https://api.siliconflow.cn
  • 实际结果:https://api.siliconflow.c/v1n 被误删)
  • 期望结果: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/v1n 被误删)

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.cnnrstrip("/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 吗?

  • Yes!

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:providerThe bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions