Skip to content
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
merged 14 commits into from
Feb 18, 2024

Conversation

ericmjl
Copy link
Owner

@ericmjl ericmjl commented Feb 16, 2024

  • 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.

…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.
Copy link

codecov bot commented Feb 17, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (34548a5) 68.84% compared to head (16f8e1b) 69.43%.

Files Patch % Lines
llamabot/bot/chatbot.py 69.23% 4 Missing ⚠️
llamabot/bot/simplebot.py 94.73% 2 Missing ⚠️
llamabot/bot/querybot.py 0.00% 1 Missing ⚠️
llamabot/cli/git.py 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

- 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]
@ericmjl ericmjl merged commit 20f50ea into main Feb 18, 2024
6 checks passed
@ericmjl ericmjl deleted the fix-streaming-#35 branch February 18, 2024 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant