-
-
Notifications
You must be signed in to change notification settings - Fork 744
fix: Remove display_generating when stream=false to prevent streaming-like behavior #1050
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Fix for display_generating Issue | ||
|
|
||
| ## Problem | ||
| When `stream=false` but `verbose=true`, the system was still showing streaming-like visual behavior ("Generating... X.Xs") because the code was using `display_generating` function even when the user explicitly set `stream=false`. | ||
|
|
||
| ## Root Cause | ||
| Two locations in `agent.py` were passing `display_generating` as `display_fn` when `stream=False` and `verbose=True`: | ||
|
|
||
| - **Line 1073**: `display_fn=display_generating if (not stream and self.verbose) else None` | ||
| - **Line 1172**: `display_fn=display_generating if (not stream and self.verbose) else None` | ||
|
|
||
| This conflated two different concepts: | ||
| - **Verbose**: Show detailed information | ||
| - **Visual Progress**: Show animated progress indicators | ||
|
|
||
| ## Solution | ||
| Changed both locations to: | ||
| ```python | ||
| display_fn=None, # Don't use display_generating when stream=False to avoid streaming-like behavior | ||
| ``` | ||
|
|
||
| ## Expected Behavior After Fix | ||
|
|
||
| | Stream | Verbose | Visual Behavior | | ||
| |--------|---------|----------------| | ||
| | False | False | No display | | ||
| | False | True | **No streaming-like behavior (FIXED)** | | ||
| | True | False | Native streaming display | | ||
| | True | True | Native streaming display | | ||
|
|
||
| ## Files Modified | ||
| - `src/praisonai-agents/praisonaiagents/agent/agent.py` - Lines 1073 and 1172 | ||
|
|
||
| ## Verification | ||
| - Test script: `test_display_generating_fix.py` | ||
| - All old problematic patterns removed | ||
| - New safe patterns implemented at both locations |
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,74 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Test script to verify that display_generating fix is working correctly. | ||
| This script checks that the problematic patterns have been removed from agent.py. | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| def test_display_generating_fix(): | ||
| """Test that the display_generating fix has been applied correctly.""" | ||
|
|
||
| agent_file = Path("src/praisonai-agents/praisonaiagents/agent/agent.py") | ||
|
|
||
| if not agent_file.exists(): | ||
| print(f"❌ ERROR: {agent_file} not found") | ||
| return False | ||
|
|
||
| content = agent_file.read_text() | ||
|
|
||
| # Check that the old problematic patterns are gone | ||
| old_pattern = r"display_fn=display_generating if \(not stream and self\.verbose\) else None" | ||
| old_matches = re.findall(old_pattern, content) | ||
|
|
||
| # Also check for the custom LLM path problematic pattern | ||
| old_custom_pattern = r"if \(not stream and self\.verbose\) and self\.console:\s*.*with Live\(\s*display_generating" | ||
| old_custom_matches = re.findall(old_custom_pattern, content, re.MULTILINE | re.DOTALL) | ||
|
|
||
| if old_matches: | ||
| print(f"❌ FAILED: Found {len(old_matches)} instances of old problematic pattern:") | ||
| print(f" 'display_fn=display_generating if (not stream and self.verbose) else None'") | ||
| return False | ||
|
|
||
| if old_custom_matches: | ||
| print(f"❌ FAILED: Found {len(old_custom_matches)} instances of old custom LLM problematic pattern:") | ||
| print(f" 'if (not stream and self.verbose) and self.console: ... display_generating'") | ||
| return False | ||
|
|
||
| # Check that the new safe patterns are present | ||
| new_pattern = r"display_fn=None,\s*# Don't use display_generating when stream=False to avoid streaming-like behavior" | ||
| new_matches = re.findall(new_pattern, content) | ||
|
|
||
| # Check for the new custom LLM path fix | ||
| new_custom_pattern = r"if False:\s*# Don't use display_generating when stream=False to avoid streaming-like behavior" | ||
| new_custom_matches = re.findall(new_custom_pattern, content) | ||
|
|
||
| expected_total = 3 # 2 OpenAI path + 1 custom LLM path | ||
| actual_total = len(new_matches) + len(new_custom_matches) | ||
|
|
||
| if actual_total < expected_total: | ||
| print(f"❌ FAILED: Expected at least {expected_total} instances of new patterns, found {actual_total}") | ||
| print(" Expected patterns:") | ||
| print(" - 'display_fn=None, # Don't use display_generating when stream=False to avoid streaming-like behavior'") | ||
| print(" - 'if False: # Don't use display_generating when stream=False to avoid streaming-like behavior'") | ||
| return False | ||
|
|
||
| print("✅ SUCCESS: display_generating fix has been applied correctly!") | ||
| print(f" - Removed old problematic patterns: 0 found (expected 0)") | ||
| print(f" - Added new safe patterns: {actual_total} found (expected >= {expected_total})") | ||
| print(f" * OpenAI path fixes: {len(new_matches)}") | ||
| print(f" * Custom LLM path fixes: {len(new_custom_matches)}") | ||
|
|
||
| # Show the context of the changes | ||
| lines = content.split('\n') | ||
| for i, line in enumerate(lines, 1): | ||
| if "Don't use display_generating when stream=False" in line: | ||
| print(f" - Line {i}: {line.strip()}") | ||
|
|
||
| return True | ||
|
|
||
| if __name__ == "__main__": | ||
| success = test_display_generating_fix() | ||
| sys.exit(0 if success else 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly aligns with the PR's goal. However, I couldn't find any calls to the
_process_stream_responsemethod within this file, which suggests it might be unused.If this method is indeed unused, it could be considered dead code and a candidate for removal to improve maintainability. If it's called from another module, it might be better to make it a public method (e.g.,
process_stream_response) and add a proper docstring explaining its purpose and parameters.