-
Notifications
You must be signed in to change notification settings - Fork 252
Fix async streaming with OpenAISpec #552
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
Conversation
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
…utils.py - Added `asyncify` decorator to convert sync functions, sync generators, async functions, and async generators to a consistent async interface. - Introduced `_stream_gen_from_thread` to handle streaming from sync generators in a separate thread, allowing for non-blocking async operations. - Enhanced error handling within the streaming generator to manage exceptions effectively.
…tionality - Enhanced the `asyncify` decorator to streamline the conversion of sync functions and generators to async counterparts. - Improved documentation within the decorator for better understanding of its behavior. - Updated imports in base.py and openai.py to utilize the new asyncify decorator, ensuring consistent async handling across the codebase.
- Removed the `_stream_gen_from_thread` and `asyncify` functions from `utils.py` to streamline async function handling. - Updated `_async_inject_context` in `base.py` to improve context injection for async functions and generators. - Enhanced `StreamingLoop` to correctly handle async generators in response encoding. - Introduced `as_async` method in `LitSpec` and `OpenAISpec` to support async specifications. - Added `_AsyncOpenAISpecWrapper` to manage async behavior for OpenAI specifications. These changes improve the overall async functionality and maintainability of the codebase.
- Introduced `_AsyncSpecWrapper` to facilitate async handling in `LitSpec`. - Updated `as_async` method in `LitSpec` to return an instance of `_AsyncSpecWrapper`. - Refactored `_AsyncOpenAISpecWrapper` to inherit from `_AsyncSpecWrapper`, streamlining async behavior for `OpenAISpec`. - Improved async request and response handling in both specifications. These changes enhance the overall async functionality and maintainability of the codebase.
Borda
approved these changes
Jun 16, 2025
…nerator requirement
- Improved the `_validate_async_methods` function to use a structured validation approach for async methods. - Introduced a dictionary to define validation rules for `decode_request`, `encode_response`, and `predict` methods. - Enhanced error handling by collecting warnings and errors separately, providing clearer feedback when async requirements are not met. - Ensured that appropriate warnings are issued and errors raised based on the validation results. These changes enhance the clarity and maintainability of async method validation in the LitAPI class.
…ing in AsyncTestStreamLitAPI
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #552 +/- ##
===================================
- Coverage 85% 85% -0%
===================================
Files 38 38
Lines 2902 2940 +38
===================================
+ Hits 2480 2504 +24
- Misses 422 436 +14 🚀 New features to boost your workflow:
|
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.
What does this PR do?
Old: users are forced to implement all the methods as async and not rely on default decode_request and encode_response method.
New (this PR): User only implements predict and rest of the methods gets automatically converted into async.
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃