Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions astrbot/core/provider/sources/openai_embedding_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, provider_config: dict, provider_settings: dict) -> None:
api_base = (
provider_config.get("embedding_api_base", "https://api.openai.com/v1")
.strip()
.rstrip("/")
.rstrip("/embeddings")
.removesuffix("/")
.removesuffix("/embeddings")
Comment on lines +30 to +31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

感谢您修复这个 bug!使用 removesuffix 确实是正确的做法。

这里有一个小建议:只将有问题的 .rstrip("/embeddings") 改为 .removesuffix("/embeddings"),并保留 .rstrip("/") 可能更好。

原因是 .rstrip("/") 可以移除末尾所有的斜杠(例如 //),比 .removesuffix("/") 只移除一个斜杠更具鲁棒性。rstrip 的问题仅在于当参数是多字符字符串时,它会将其作为字符集处理;对于单个字符 / 则是安全且符合预期的。

这样修改后,代码既能修复 bug,又能更好地处理用户可能输入的多余斜杠。

Suggested change
.removesuffix("/")
.removesuffix("/embeddings")
.rstrip("/")
.removesuffix("/embeddings")

)
if api_base and not api_base.endswith("/v1") and not api_base.endswith("/v4"):
# /v4 see #5699
Expand Down
Loading