Skip to content

Fix: Remove stop parameter for o4-mini model #2663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/crewai/llm.py
Original file line number Diff line number Diff line change
@@ -358,7 +358,12 @@ def _prepare_completion_params(
}

# Remove None values from params
return {k: v for k, v in params.items() if v is not None}
params = {k: v for k, v in params.items() if v is not None}

if "o4-mini" in self.model:
params.pop("stop", None)

return params

def _handle_streaming_response(
self,
36 changes: 36 additions & 0 deletions tests/llm_test.py
Original file line number Diff line number Diff line change
@@ -533,3 +533,39 @@ def test_handle_streaming_tool_calls_no_tools(mock_emit):
expected_completed_llm_call=1,
expected_final_chunk_result=response,
)


def test_llm_o4_mini_stop_parameter():
"""Test that o4-mini model works correctly without stop parameter."""
llm = LLM(model="o4-mini", stop=["STOP", "END"])

# Check that stop parameter is set
assert llm.stop == ["STOP", "END"]

params = llm._prepare_completion_params(messages=[{"role": "user", "content": "Hello"}])

assert "stop" not in params

with patch("litellm.completion") as mock_completion:
# Create a mock response
mock_message = MagicMock()
mock_message.content = "Test response"
mock_choice = MagicMock()
mock_choice.message = mock_message
mock_response = MagicMock()
mock_response.choices = [mock_choice]
mock_response.usage = {
"prompt_tokens": 5,
"completion_tokens": 5,
"total_tokens": 10,
}

# Set up the mock to return our response
mock_completion.return_value = mock_response

response = llm.call(messages=[{"role": "user", "content": "Hello, world!"}])

assert response == "Test response"

call_args = mock_completion.call_args[1]
assert "stop" not in call_args