Fix issue #2843: Exclude stop parameter for models that don't support it #2845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix issue #2843: Exclude stop parameter for models that don't support it
Description
This PR fixes issue #2843 where using the OpenAI O3 model with CrewAI was causing a BadRequestError due to the 'stop' parameter being passed to models that don't support it.
The fix:
supports_stop_words()
method in the LLM class to explicitly check for models known not to support stop words (o3, o3-mini, o4-mini)call()
method to exclude the 'stop' parameter when the model doesn't support itTesting
Added the following tests:
test_supports_stop_words_for_o3_model
: Verifies thatsupports_stop_words()
returns False for o3 modeltest_supports_stop_words_for_o4_mini_model
: Verifies thatsupports_stop_words()
returns False for o4-mini modeltest_llm_call_excludes_stop_parameter_for_unsupported_models
: Verifies that the 'stop' parameter is excluded when calling models that don't support itAll tests pass successfully.
Link to Devin run
https://app.devin.ai/sessions/4b634d0eb22449f9be7b7a5b0ea35b50
Requested by
Joe Moura ([email protected])
Fixes #2843