mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(dashscope): improve get_complete_url guard to prevent double-path append
The endswith check could miss URLs with trailing slashes or /chat/completions already present after a query string. Align with OpenAIGPTConfig behavior: strip trailing slash and check if endpoint is anywhere in the URL. Fixes #28429
This commit is contained in:
parent
a2f9963a1d
commit
166f49e1d0
1 changed files with 7 additions and 3 deletions
|
|
@ -73,12 +73,16 @@ class DashScopeChatConfig(OpenAIGPTConfig):
|
|||
stream: Optional[bool] = None,
|
||||
) -> str:
|
||||
"""
|
||||
If api_base is not provided, use the default DashScope /chat/completions endpoint.
|
||||
If api_base is not provided, use the default DashScope base URL.
|
||||
Appends /chat/completions only when not already present in the URL,
|
||||
matching the behavior of OpenAIGPTConfig.get_complete_url.
|
||||
"""
|
||||
if not api_base:
|
||||
api_base = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
|
||||
if not api_base.endswith("/chat/completions"):
|
||||
api_base = f"{api_base}/chat/completions"
|
||||
endpoint = "chat/completions"
|
||||
api_base = api_base.rstrip("/")
|
||||
if endpoint not in api_base:
|
||||
api_base = f"{api_base}/{endpoint}"
|
||||
|
||||
return api_base
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue