fix(cohere,replicate): stop declaring silently-dropped params as supported

Cohere v1/v2 declared tool_choice and Replicate declared tools/tool_choice/functions/function_call/seed in get_supported_openai_params, but map_openai_params has no branch for any of them and no later layer picks them up, so the params vanished without error even with drop_params=False. Replicate's tools case silently degraded tool-calling requests to plain completions.

Remove them from the supported lists so get_optional_params raises UnsupportedParamsError by default (explicit drop with drop_params=True), consistent with litellm's drop_params contract. Regression tests included; ReplicateConfig remains the path for model-specific inputs like seed.

Fixes #43613
This commit is contained in:
JingHao-Leon 2026-09-29 04:50:06 +08:00
parent 9fd78ff6f4
commit e17c2ac016
6 changed files with 75 additions and 7 deletions

View file

@ -144,7 +144,6 @@ class CohereChatConfig(BaseConfig):
"stop",
"n",
"tools",
"tool_choice",
"seed",
"extra_headers",
]

View file

@ -128,7 +128,6 @@ class CohereV2ChatConfig(OpenAIGPTConfig):
"stop",
"n",
"tools",
"tool_choice",
"seed",
"extra_headers",
]

View file

@ -91,11 +91,6 @@ class ReplicateConfig(BaseConfig):
"max_tokens",
"top_p",
"stop",
"seed",
"tools",
"tool_choice",
"functions",
"function_call",
]
def map_openai_params(

View file

@ -0,0 +1,33 @@
import pytest
from litellm.llms.cohere.chat.transformation import CohereChatConfig
from litellm.llms.cohere.chat.v2_transformation import CohereV2ChatConfig
from litellm.utils import UnsupportedParamsError, get_optional_params
@pytest.mark.parametrize("config_cls", [CohereChatConfig, CohereV2ChatConfig])
def test_tool_choice_not_declared(config_cls):
params = config_cls().get_supported_openai_params(model="command-r")
assert "tool_choice" not in params
def test_tool_choice_raises_unsupported_params_error():
# tool_choice used to be declared but silently dropped; with drop_params=False
# (the default) litellm must surface that instead of ignoring it
with pytest.raises(UnsupportedParamsError):
get_optional_params(
model="command-r",
custom_llm_provider="cohere",
tool_choice="auto",
request_timeout=10,
num_retries=0,
)
def test_stop_still_maps_to_stop_sequences():
result = CohereChatConfig().map_openai_params(
non_default_params={"stop": ["X"]},
optional_params={},
model="command-r",
drop_params=False,
)
assert result["stop_sequences"] == ["X"]

View file

@ -0,0 +1,42 @@
import pytest
from litellm.llms.replicate.chat.transformation import ReplicateConfig
from litellm.utils import UnsupportedParamsError, get_optional_params
REMOVED_PARAMS = {
"tools": [{"type": "function", "function": {"name": "f", "parameters": {"type": "object", "properties": {}}}}],
"tool_choice": "auto",
"functions": [{"name": "f", "parameters": {}}],
"function_call": "auto",
"seed": 42,
}
def test_tool_params_not_declared():
supported = ReplicateConfig().get_supported_openai_params(model="meta/meta-llama-3-70b-instruct")
for param in REMOVED_PARAMS:
assert param not in supported
@pytest.mark.parametrize("param,value", sorted(REMOVED_PARAMS.items()))
def test_removed_params_raise_unsupported_params_error(param, value):
# these used to be declared but were silently dropped, degrading tool-calling
# requests to plain completions; with drop_params=False (the default) litellm
# must surface that instead of ignoring it
with pytest.raises(UnsupportedParamsError):
get_optional_params(
model="meta/meta-llama-3-70b-instruct",
custom_llm_provider="replicate",
**{param: value},
request_timeout=10,
num_retries=0,
)
def test_stop_still_maps_to_stop_sequences():
result = ReplicateConfig().map_openai_params(
non_default_params={"stop": ["X"]},
optional_params={},
model="meta/meta-llama-3-70b-instruct",
drop_params=False,
)
assert result["stop_sequences"] == ["X"]