mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-21 00:21:49 +00:00
fix(bedrock): extend maxTokens minimum clamp to xAI Grok models on Converse
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
3673327fc4
commit
665327249d
2 changed files with 12 additions and 5 deletions
|
|
@ -107,7 +107,7 @@ BEDROCK_COMPUTER_USE_TOOLS: Final = [
|
|||
"bash_",
|
||||
"text_editor_",
|
||||
]
|
||||
BEDROCK_OPENAI_GPT_MIN_MAX_TOKENS: Final = 16
|
||||
BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS: Final = 16
|
||||
|
||||
# Beta header patterns that are not supported by Bedrock Converse API
|
||||
# These will be filtered out to prevent errors
|
||||
|
|
@ -378,10 +378,14 @@ class AmazonConverseConfig(BaseConfig):
|
|||
def _is_openai_gpt_reasoning_model(model: str) -> bool:
|
||||
return re.search(r"openai\.gpt-\d", model) is not None
|
||||
|
||||
@staticmethod
|
||||
def _requires_min_max_tokens(model: str) -> bool:
|
||||
return re.search(r"openai\.gpt-\d|xai\.grok-", model) is not None
|
||||
|
||||
@staticmethod
|
||||
def _enforce_min_max_tokens(max_tokens: object) -> object:
|
||||
if isinstance(max_tokens, int) and max_tokens < BEDROCK_OPENAI_GPT_MIN_MAX_TOKENS:
|
||||
return BEDROCK_OPENAI_GPT_MIN_MAX_TOKENS
|
||||
if isinstance(max_tokens, int) and max_tokens < BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS:
|
||||
return BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS
|
||||
return max_tokens
|
||||
|
||||
def _is_nova_2_model(self, model: str) -> bool:
|
||||
|
|
@ -1008,7 +1012,7 @@ class AmazonConverseConfig(BaseConfig):
|
|||
if param == "max_tokens" or param == "max_completion_tokens":
|
||||
optional_params["maxTokens"] = (
|
||||
self._enforce_min_max_tokens(value)
|
||||
if self._is_openai_gpt_reasoning_model(model) and isinstance(value, int)
|
||||
if self._requires_min_max_tokens(model) and isinstance(value, int)
|
||||
else value
|
||||
)
|
||||
if param == "stream":
|
||||
|
|
|
|||
|
|
@ -463,10 +463,13 @@ def test_reasoning_with_forced_tool_choice_switches_to_auto():
|
|||
("us.openai.gpt-6-astra", "max_tokens", 1, 16),
|
||||
("us.openai.gpt-6-astra", "max_completion_tokens", 1, 16),
|
||||
("us.openai.gpt-6-astra", "max_tokens", 64, 64),
|
||||
("us.xai.grok-4.6", "max_tokens", 1, 16),
|
||||
("global.xai.grok-4.6", "max_completion_tokens", 1, 16),
|
||||
("us.xai.grok-4.6", "max_tokens", 32, 32),
|
||||
("anthropic.claude-sonnet-4-5-20250929-v1:0", "max_tokens", 1, 1),
|
||||
],
|
||||
)
|
||||
def test_map_openai_params_enforces_minimum_max_tokens_for_openai_gpt_reasoning_models(
|
||||
def test_map_openai_params_enforces_minimum_max_tokens_for_openai_compat_models(
|
||||
model: str, param: str, value: int, expected_max_tokens: int
|
||||
):
|
||||
optional_params = AmazonConverseConfig().map_openai_params(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue