-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: enhance SimpleBot streaming capabilities and update notebook examples #43
Merged
Conversation
This file contains 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
…amples - Implement stream target validation and support for stdout, panel, and API streaming in SimpleBot - Update Jupyter notebook examples to demonstrate new streaming functionality - Refactor SimpleBot `__call__` method to handle different streaming targets - Adjust typing annotations to include Generator for stream API - Update Python version in notebook metadata to 3.11.7 This commit introduces new streaming capabilities to the SimpleBot class, allowing users to specify the target for streaming responses. The Jupyter notebook examples have been updated to showcase these new features, and the code has been refactored to handle the different streaming options more cleanly. Additionally, the typing annotations have been adjusted to reflect the use of generators for the stream API, and the Python version in the notebook metadata has been updated.
- The 'stream' boolean parameter has been replaced with 'stream_target' to allow for more flexible output options. - 'stream_target' can be one of "stdout", "panel", or "api", providing better control over where the bot's responses are directed. - Updated all instances where 'stream' was used, including in tests, to use the new 'stream_target' parameter. - This change is backward-incompatible and requires updates to existing code that uses the 'stream' parameter. BREAKING CHANGE: The 'stream' parameter in ChatBot and SimpleBot constructors has been removed in favor of 'stream_target'. Update your code to use the new parameter.
The streaming.ipynb notebook in the docs/examples directory has been removed as it was outdated and no longer reflected the current best practices or library usage. Users should refer to the updated documentation and examples for guidance on implementing streaming functionality.
- Add ValueError when 'api' is passed as stream_target to prevent unsupported operations - Replace autorecord function with match-case structure for different stream targets - Introduce Union type for __call__ return type to support Generator - Remove autorecord import as it's no longer used BREAKING CHANGE: The __call__ method now can return a Generator in addition to AIMessage, which changes the expected return type for consumers of the ChatBot class. The 'api' stream_target is no longer supported and will raise a ValueError.
- Removed the `chat_history_class` parameter from the ChatBot constructor. - Added `**completion_kwargs` to pass additional keyword arguments to the completion function. - Ensured `**completion_kwargs` are passed to the superclass constructor. BREAKING CHANGE: The constructor no longer accepts `chat_history_class` as a parameter. Clients relying on this parameter will need to update their code to use the new `completion_kwargs` parameter for passing additional options to the completion function.
- Modify the `test_chatbot_call` function to use a predefined mock response - Update the assertion to check for the new mock response content - Ensure the test reflects the behavior of the ChatBot with a mocked response This change improves the test's predictability by using a fixed response.
- Update `SimpleBot` methods to correctly access `delta` using dictionary syntax. - Ensure message concatenation includes all response chunks. - Remove pinned version of `litellm` in `environment.yml` to allow flexible updates. - Adjust test to expect prefixed space in `test_simplebot.py`. refactor: remove debug print statement from SimpleBot - Remove a print statement that was likely used for debugging purposes.
…t message echo - Removed a debug print statement from the response loop in SimpleBot class. - Simplified the commit message handling in compose_commit function by directly invoking the bot without echoing the message content. This change does not affect the API or functionality, hence there is no breaking change.
- Remove explicit mocker patching for generate_response in test_chatbot_repr. - Add mock_response parameter to ChatBot constructor to facilitate testing. - Update assertions to check for the actual response content in the chatbot's representation. This change streamlines the testing process by utilizing a constructor parameter for mocking responses instead of patching methods, making the test more straightforward and maintainable.
…tbot_repr - Updated test_chatbot_repr to reflect changes in ChatBot's __repr__ method and removed outdated comments. - The removal of test_chatbot_call does not affect the external behavior or API, hence no breaking change is indicated. - Cleaned up imports by removing the unused AIMessage import.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
==========================================
+ Coverage 68.84% 69.43% +0.58%
==========================================
Files 53 54 +1
Lines 1775 1809 +34
==========================================
+ Hits 1222 1256 +34
Misses 553 553 ☔ View full report in Codecov by Sentry. |
- Add new test `test_simple_bot_stream_stdout` to check if SimpleBot's stream API to stdout behaves as expected - Introduce `test_simple_bot_stream_panel_or_api` to verify streaming to panel or API endpoints - Include `mock_response` in test scenarios to ensure dynamic response testing - Ensure that the `result` from SimpleBot is an instance of `AIMessage` and contains the `mock_response` in `test_simple_bot_stream_stdout` - Validate that each response in the generator from SimpleBot is a string and part of `mock_response` in `test_simple_bot_stream_panel_or_api` This update extends the test coverage for SimpleBot's streaming capabilities, ensuring that the bot's responses are correctly streamed to different targets and that the responses are as expected.
- Remove the `stream` parameter from QueryBot constructor to simplify the interface. - Replace `generate_response` with `stream_stdout` to clarify the output method. This change improves the readability and maintainability of the QueryBot class by making the output streaming behavior explicit and removing an unnecessary constructor parameter. The `stream_stdout` method now clearly indicates that the bot's response is intended for standard output.
- Implement a new test case for the QueryBot class to ensure proper initialization with given parameters. - Utilize property-based testing with Hypothesis to generate a wide range of input scenarios. - Verify that the QueryBot instance returns an AIMessage with the expected mock response content. - Suppress health checks for function-scoped fixtures and remove deadline constraints to accommodate the testing of asynchronous operations.
- Remove unused import of AIMessage from test_querybot.py - Update test_querybot_init to instantiate QueryBot without assigning to a variable - Remove assertions related to AIMessage as they are no longer relevant This change streamlines the QueryBot initialization test by removing unnecessary code and assertions that are not pertinent to the initialization process. [END COMMIT MESSAGE]
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.
__call__
method to handle different streaming targetsThis commit introduces new streaming capabilities to the SimpleBot class, allowing users to specify the target for streaming responses. The Jupyter notebook examples have been updated to showcase these new features, and the code has been refactored to handle the different streaming options more cleanly. Additionally, the typing annotations have been adjusted to reflect the use of generators for the stream API, and the Python version in the notebook metadata has been updated.