[Bug Fix] grok-4 does not support the stop param (#12646)
* bug fix - using stop reason with grok 4 * fixes for XAI stop params * test_xai_grok_4_stop_not_supported * test_xai_grok_4_stop_not_supported
This commit is contained in:
parent
604075a36c
commit
e8a748161f
@ -50,7 +50,7 @@ class XAIChatConfig(OpenAIGPTConfig):
|
||||
"web_search_options",
|
||||
]
|
||||
# for some reason, grok-3-mini does not support stop tokens
|
||||
if "grok-3-mini" not in model:
|
||||
if self._supports_stop_reason(model):
|
||||
base_openai_params.append("stop")
|
||||
try:
|
||||
if litellm.supports_reasoning(
|
||||
@ -61,6 +61,13 @@ class XAIChatConfig(OpenAIGPTConfig):
|
||||
verbose_logger.debug(f"Error checking if model supports reasoning: {e}")
|
||||
|
||||
return base_openai_params
|
||||
|
||||
def _supports_stop_reason(self, model: str) -> bool:
|
||||
if "grok-3-mini" in model:
|
||||
return False
|
||||
elif "grok-4" in model:
|
||||
return False
|
||||
return True
|
||||
|
||||
def map_openai_params(
|
||||
self,
|
||||
|
||||
@ -118,6 +118,21 @@ def test_xai_check_for_stop_in_supported_params():
|
||||
assert "stop" not in supported_params
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model", ["xai/grok-4", "xai/grok-4-0709"])
|
||||
def test_xai_grok_4_stop_not_supported(model):
|
||||
"""
|
||||
Test that grok-4 models do not support the stop parameter
|
||||
|
||||
Issue: https://github.com/BerriAI/litellm/issues/12635
|
||||
"""
|
||||
supported_params = XAIChatConfig().get_supported_openai_params(
|
||||
model=model
|
||||
)
|
||||
assert "stop" not in supported_params
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stream", [False, True])
|
||||
def test_completion_xai(stream):
|
||||
try:
|
||||
@ -130,9 +145,9 @@ def test_completion_xai(stream):
|
||||
},
|
||||
]
|
||||
response = completion(
|
||||
model="xai/grok-3-mini-beta",
|
||||
model="xai/grok-4",
|
||||
messages=messages,
|
||||
stream=stream,
|
||||
stream=stream
|
||||
)
|
||||
print(response)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user