mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(embedding): respect drop_params for unsupported dimensions parameter
The OpenAI-provider branch in `get_optional_params_embeddings` hard-raised `UnsupportedParamsError` whenever `dimensions` was passed to a non `text-embedding-3` model, even though the error message itself instructed users to set `litellm.drop_params=True`. The flag (per-call and global) was never consulted on this path, breaking the documented escape hatch for users proxying to vLLM/TEI/Ollama-compat embedding servers via the `openai/...` model prefix. Now mirror the `drop_params` handling already used by `_check_valid_arg` in the same function: when either `drop_params=True` (per-call) or `litellm.drop_params=True` (global) is set, silently strip `dimensions` from `non_default_params` and continue; otherwise preserve the existing error to keep current behavior for users who have not opted in. Adds two regression tests (per-call and global flag) and pins the existing raise-by-default behavior against accidental future drift. Fixes #26787 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3e1479c052
commit
abf389830a
2 changed files with 75 additions and 11 deletions
|
|
@ -3309,12 +3309,19 @@ def get_optional_params_embeddings( # noqa: PLR0915
|
|||
and "dimensions" in non_default_params.keys()
|
||||
and "dimensions" not in (allowed_openai_params or [])
|
||||
):
|
||||
raise UnsupportedParamsError(
|
||||
status_code=500,
|
||||
message="Setting dimensions is not supported for OpenAI `text-embedding-3` and later models. To drop it from the call, set `litellm.drop_params = True`.",
|
||||
)
|
||||
else:
|
||||
optional_params = non_default_params
|
||||
# Honor drop_params (per-call) and litellm.drop_params (global) the same
|
||||
# way `_check_valid_arg` does above. The raised error message itself
|
||||
# tells users to set `drop_params=True`, so respect it here.
|
||||
if litellm.drop_params is True or (
|
||||
drop_params is not None and drop_params is True
|
||||
):
|
||||
non_default_params.pop("dimensions", None)
|
||||
else:
|
||||
raise UnsupportedParamsError(
|
||||
status_code=500,
|
||||
message="Setting dimensions is not supported for OpenAI `text-embedding-3` and later models. To drop it from the call, set `litellm.drop_params = True`.",
|
||||
)
|
||||
optional_params = non_default_params
|
||||
elif custom_llm_provider == "triton":
|
||||
supported_params = get_supported_openai_params(
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -97,12 +97,69 @@ def test_openai_non_text_embedding_3_without_allowed_openai_params_raises():
|
|||
"""
|
||||
from litellm.exceptions import UnsupportedParamsError
|
||||
|
||||
model, custom_llm_provider, _, _ = get_llm_provider(
|
||||
model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2"
|
||||
)
|
||||
with pytest.raises(UnsupportedParamsError):
|
||||
get_optional_params_embeddings(
|
||||
# ensure global drop_params is off (other tests in this file flip it on)
|
||||
prev_drop_params = litellm.drop_params
|
||||
litellm.drop_params = False
|
||||
try:
|
||||
model, custom_llm_provider, _, _ = get_llm_provider(
|
||||
model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2"
|
||||
)
|
||||
with pytest.raises(UnsupportedParamsError):
|
||||
get_optional_params_embeddings(
|
||||
model=model,
|
||||
dimensions=1024,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
finally:
|
||||
litellm.drop_params = prev_drop_params
|
||||
|
||||
|
||||
def test_openai_non_text_embedding_3_drop_params_per_call():
|
||||
"""
|
||||
Regression for https://github.com/BerriAI/litellm/issues/26787
|
||||
|
||||
When drop_params=True is passed per-call, `dimensions` should be silently
|
||||
stripped for a non-`text-embedding-3` OpenAI-provider model instead of
|
||||
raising UnsupportedParamsError.
|
||||
"""
|
||||
prev_drop_params = litellm.drop_params
|
||||
litellm.drop_params = False # ensure only per-call flag is in effect
|
||||
try:
|
||||
model, custom_llm_provider, _, _ = get_llm_provider(
|
||||
model="openai/Qwen/Qwen3-Embedding-0.6B"
|
||||
)
|
||||
optional_params = get_optional_params_embeddings(
|
||||
model=model,
|
||||
dimensions=1024,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
drop_params=True,
|
||||
)
|
||||
print(f"received optional_params: {optional_params}")
|
||||
assert "dimensions" not in optional_params
|
||||
finally:
|
||||
litellm.drop_params = prev_drop_params
|
||||
|
||||
|
||||
def test_openai_non_text_embedding_3_drop_params_global():
|
||||
"""
|
||||
Regression for https://github.com/BerriAI/litellm/issues/26787
|
||||
|
||||
When `litellm.drop_params = True` is set globally, `dimensions` should be
|
||||
silently stripped for a non-`text-embedding-3` OpenAI-provider model
|
||||
instead of raising UnsupportedParamsError.
|
||||
"""
|
||||
prev_drop_params = litellm.drop_params
|
||||
litellm.drop_params = True
|
||||
try:
|
||||
model, custom_llm_provider, _, _ = get_llm_provider(
|
||||
model="openai/Qwen/Qwen3-Embedding-0.6B"
|
||||
)
|
||||
optional_params = get_optional_params_embeddings(
|
||||
model=model,
|
||||
dimensions=1024,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
print(f"received optional_params: {optional_params}")
|
||||
assert "dimensions" not in optional_params
|
||||
finally:
|
||||
litellm.drop_params = prev_drop_params
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue