fix(dashscope): forward user param in embed, honour api_base in rerank URL, and unify API-key env fallback across embed/rerank

This commit is contained in:
yimao 2026-05-12 10:27:32 +08:00
parent 9f7763edd4
commit 5495d70ba0
2 changed files with 8 additions and 3 deletions

View file

@ -73,7 +73,11 @@ class DashScopeEmbeddingConfig(BaseEmbeddingConfig):
api_base: Optional[str] = None,
) -> dict:
if api_key is None:
raise ValueError("api_key is required for DashScope authentication")
api_key = get_secret_str("DASHSCOPE_API_KEY")
if api_key is None:
raise ValueError(
"DashScope API key is required. Set 'DASHSCOPE_API_KEY' env var or pass api_key explicitly."
)
default_headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
@ -106,7 +110,7 @@ class DashScopeEmbeddingConfig(BaseEmbeddingConfig):
"model": model,
"input": input,
}
for key in ("dimensions", "encoding_format"):
for key in ("dimensions", "encoding_format", "user"):
value = optional_params.get(key)
if value is not None:
data[key] = value

View file

@ -77,7 +77,8 @@ class DashScopeRerankConfig(BaseRerankConfig):
if cleaned.endswith("/v1"):
return f"{cleaned}/reranks"
return DEFAULT_RERANK_URL
# Unknown base: append /reranks rather than silently ignoring the caller's api_base.
return f"{cleaned}/reranks"
def validate_environment(
self,