Fix #377: Resolve OpenAI client streaming/non-streaming parser mixing#446
Open
pxkundu wants to merge 3 commits into
Open
Fix #377: Resolve OpenAI client streaming/non-streaming parser mixing#446pxkundu wants to merge 3 commits into
pxkundu wants to merge 3 commits into
Conversation
…orm compatibility - Replace subprocess.call(['wget', ...]) with urllib.request.urlretrieve() - Fix dataset download failure on Windows and minimal Docker images - Add improved error handling with specific HTTP status codes - Ensure directory creation before download - Maintain backward compatibility and all existing functionality Resolves: 'FileNotFoundError: The system cannot find the file specified' on Windows when downloading BigBenchHard datasets.
…rser mixing - Replace problematic instance variable assignment with dynamic parser selection - Fix issue where self.response_parser persisted across calls causing mode confusion - Add type-specific logic to distinguish Response, AsyncIterable, and Iterable objects - Exclude basic types (str, bytes, dict) from streaming detection - Ensure correct parser is always selected based on completion type Resolves: OpenAI client getting 'stuck' in streaming or non-streaming mode after switching between stream=True and stream=False calls.
- Fix bedrock client AWS credential import issue with lazy initialization - Update OpenAI client tests to reflect dynamic parser selection behavior - Remove dependency on response_parser instance variable in tests - Ensure all tests pass with the new parser switching implementation This resolves the CI test failures in PR SylphAI-Inc#446 while maintaining the fix for issue SylphAI-Inc#377.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #377: Resolve OpenAI client streaming/non-streaming parser mixing
Problem
The OpenAI client gets "stuck" in streaming or non-streaming mode after switching between
stream=Trueandstream=Falsecalls. This happens because theself.response_parserinstance variable is modified during each call and persists across subsequent calls, causing the wrong parser to be used.Root Cause
The issue occurs in these lines:
self.response_parser = self.streaming_response_parser_sync(for streaming)self.response_parser = self.non_streaming_response_parser(for non-streaming)The instance variable assignment means:
generator(stream=True)→ Setsself.response_parser = streaming_parsergenerator(stream=False)→ Setsself.response_parser = non_streaming_parsergenerator(stream=True)→ Butparse_chat_completion()still uses the oldself.response_parserSolution
parse_chat_completion()self.response_parserassignmentsBenefits
Testing
Code Changes
parse_chat_completion(): Dynamic parser selection based on completion typeself.response_parserassignmentself.response_parserassignmentType of Change
Impact
This fix resolves a critical issue that made the OpenAI client unreliable when users needed to dynamically switch between streaming and non-streaming modes in the same application session.
Fixes #377