mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(embeddings): only drop dimensions for openai_compatible_providers when drop_params=True
The previous implementation unconditionally raised UnsupportedParamsError whenever 'dimensions' was passed to an openai_compatible_provider and the model name did not contain 'text-embedding-3', regardless of drop_params. This was backwards-incompatible: providers such as Jina AI, Cohere, or any OpenRouter-routed model that legitimately accept 'dimensions' would suddenly raise a client-side error for callers who had never set drop_params. The correct behaviour mirrors how other unsupported-param guards work in LiteLLM: only drop (or act on) the parameter when the caller has opted in via drop_params=True. When drop_params is not set, forward the parameter as-is and let the upstream endpoint respond.
This commit is contained in:
parent
986c0eb900
commit
fe622faa04
1 changed files with 8 additions and 15 deletions
|
|
@ -3454,27 +3454,20 @@ def get_optional_params_embeddings( # noqa: PLR0915
|
|||
optional_params = non_default_params
|
||||
else:
|
||||
# openai_compatible_providers (e.g. hosted_vllm, openrouter, etc.)
|
||||
# Pass all params through, but honour drop_params for `dimensions`
|
||||
# because many vLLM / compatible endpoints don't support it and return
|
||||
# 422 when it is present. Only text-embedding-3-* models support it.
|
||||
# When drop_params=True, silently drop `dimensions` for models whose
|
||||
# names do not contain "text-embedding-3", because many compatible
|
||||
# endpoints (vLLM, etc.) return 422 when the parameter is present.
|
||||
# When drop_params is not set we forward the parameter as-is: some
|
||||
# compatible providers (Jina AI, Cohere via OpenRouter, …) do support
|
||||
# `dimensions`, so raising unconditionally would break them.
|
||||
optional_params = non_default_params.copy()
|
||||
if (
|
||||
"dimensions" in optional_params
|
||||
and model is not None
|
||||
and "text-embedding-3" not in model
|
||||
and (litellm.drop_params is True or drop_params is True)
|
||||
):
|
||||
if litellm.drop_params is True or drop_params is True:
|
||||
optional_params.pop("dimensions")
|
||||
else:
|
||||
raise UnsupportedParamsError(
|
||||
status_code=500,
|
||||
message=(
|
||||
f"Setting 'dimensions' is not supported for model '{model}' "
|
||||
f"with provider '{custom_llm_provider}'. Only text-embedding-3-* "
|
||||
"models support this parameter. To drop it from the call, set "
|
||||
"`litellm.drop_params = True`."
|
||||
),
|
||||
)
|
||||
optional_params.pop("dimensions")
|
||||
|
||||
final_params = add_provider_specific_params_to_optional_params(
|
||||
optional_params=optional_params,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue