-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix no response / null response from LLM #3591
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
Open
Vidit-Ostwal
wants to merge
15
commits into
crewAIInc:main
Choose a base branch
from
Vidit-Ostwal:Invalid_response_from_LLM
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58ba7c5
vo/fix/none_empty_response
Vidit-Ostwal 1cde3fa
Merge branch 'main' into Invalid_response_from_LLM
Vidit-Ostwal cfe05b0
Added support for null response check
Vidit-Ostwal cbd7b22
Refractor the is_context_length_exceeded function
Vidit-Ostwal 0c52b0a
Removed unnessary import
Vidit-Ostwal 7379156
Ruff checks
Vidit-Ostwal 703b163
Added test cases
Vidit-Ostwal f15d87a
Merge branch 'main' into Invalid_response_from_LLM
Vidit-Ostwal 07bb2aa
Test case for the agent_executor
Vidit-Ostwal a0aae6f
Mypy fixed
Vidit-Ostwal 29123db
more Mypy errors
Vidit-Ostwal 9742d6d
more mypy fixed
Vidit-Ostwal c66bdea
fixed the logic
Vidit-Ostwal a3d1666
removed debug statements
Vidit-Ostwal 8722eb2
Merge branch 'main' into Invalid_response_from_LLM
Vidit-Ostwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import pytest | ||
| from unittest.mock import MagicMock | ||
| from crewai.utilities.agent_utils import is_null_response_because_context_length_exceeded | ||
|
|
||
| def test_is_null_response_because_context_length_exceeded_true(): | ||
| """ | ||
| Test that the function returns True when the exception is a ValueError | ||
| with 'None or empty' and there are messages. | ||
| """ | ||
| # Arrange | ||
| mock_llm = MagicMock() | ||
| mock_llm.get_context_window_size.return_value = 10 | ||
| exception = ValueError("Invalid response from LLM call - None or empty.") | ||
| messages = [{"content": "This is a test message."}] | ||
|
|
||
| # Act | ||
| result = is_null_response_because_context_length_exceeded(exception, messages, mock_llm) | ||
|
|
||
| # Assert | ||
| assert result is True | ||
|
|
||
|
|
||
| def test_is_null_response_because_context_length_exceeded_false_wrong_exception(): | ||
| """ | ||
| Test that the function returns False when the exception is not a ValueError. | ||
| """ | ||
| # Arrange | ||
| mock_llm = MagicMock() | ||
| mock_llm.get_context_window_size.return_value = 10 | ||
| exception = TypeError("Some other error.") | ||
| messages = [{"content": "This is a test message."}] | ||
|
|
||
| # Act | ||
| result = is_null_response_because_context_length_exceeded(exception, messages, mock_llm) | ||
|
|
||
| # Assert | ||
| assert result is False | ||
|
|
||
|
|
||
| def test_is_null_response_because_context_length_exceeded_false_wrong_message(): | ||
| """ | ||
| Test that the function returns False when the exception message does not | ||
| contain 'None or empty'. | ||
| """ | ||
| # Arrange | ||
| mock_llm = MagicMock() | ||
| mock_llm.get_context_window_size.return_value = 10 | ||
| exception = ValueError("Another value error.") | ||
| messages = [{"content": "This is a test message."}] | ||
|
|
||
| # Act | ||
| result = is_null_response_because_context_length_exceeded(exception, messages, mock_llm) | ||
|
|
||
| # Assert | ||
| assert result is False | ||
|
|
||
|
|
||
| def test_is_null_response_because_context_length_exceeded_false_empty_messages(): | ||
| """ | ||
| Test that the function returns False when the messages list is empty. | ||
| """ | ||
| # Arrange | ||
| mock_llm = MagicMock() | ||
| mock_llm.get_context_window_size.return_value = 10 | ||
| exception = ValueError("Invalid response from LLM call - None or empty.") | ||
| messages = [] | ||
|
|
||
| # Act | ||
| result = is_null_response_because_context_length_exceeded(exception, messages, mock_llm) | ||
|
|
||
| # Assert | ||
| assert result is False | ||
|
|
||
|
|
||
| def test_is_null_response_because_context_length_exceeded_false(): | ||
| """ | ||
| Test that the function returns True when the exception is a ValueError | ||
| with 'None or empty' and there are messages. | ||
| """ | ||
| # Arrange | ||
| mock_llm = MagicMock() | ||
| mock_llm.get_context_window_size.return_value = 50 | ||
| exception = ValueError("Invalid response from LLM call - None or empty.") | ||
| messages = [{"content": "This is a test message."}] | ||
|
|
||
| # Act | ||
| result = is_null_response_because_context_length_exceeded(exception, messages, mock_llm) | ||
|
|
||
| # Assert | ||
| assert result is False | ||
|
|
||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.