fix: 统一前后端API_URL处理规则: /结尾忽略v1版本,#结尾强制使用输入地址。 优化公告区域位置

This commit is contained in:
兰志宏
2025-03-04 18:24:37 +08:00
parent 661741e25d
commit 0847e557fb
6 changed files with 282 additions and 42 deletions

23
utils/api_utils.py Normal file
View File

@@ -0,0 +1,23 @@
class APIUtils:
@staticmethod
def format_api_url(base_url: str) -> str:
"""
格式化 API URL
/结尾忽略v1版本#结尾强制使用输入地址
Args:
base_url: 基础 API URL
Returns:
str: 格式化后的完整 API URL
"""
if not base_url:
return ""
if base_url.endswith('/'):
return f"{base_url}chat/completions"
elif base_url.endswith('#'):
return base_url.replace('#', '')
else:
return f"{base_url}/v1/chat/completions"