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: add EventManager to centralize callbacks #3434

Merged
merged 55 commits into from
Sep 2, 2024

Conversation

ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Aug 19, 2024

This adds the EventManager that takes care of sending the events to the frontend in the build_flow but will also allow us to send real time data throughout the build process from calls coming from the components.

Copy link
Contributor

Pull Request Validation Report

This comment is automatically generated by Conventional PR

Whitelist Report

Whitelist Active Result
Pull request is a draft and should be ignored
Pull request is made by a whitelisted user and should be ignored
Pull request is submitted by a bot and should be ignored
Pull request is submitted by administrators and should be ignored

Result

Pull request matches with one (or more) enabled whitelist criteria. Pull request validation is skipped.

Last Modified at 19 Aug 24 19:24 UTC

@github-actions github-actions bot added the enhancement New feature or request label Aug 19, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-3434.dmtpw4p5recq1.amplifyapp.com

@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from b90a1d2 to b8ad9eb Compare August 19, 2024 20:34
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 20, 2024
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch 4 times, most recently from 3946f9f to ec4aa65 Compare August 23, 2024 20:38
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from 5efc982 to 1db1b0e Compare August 28, 2024 19:39
@ogabrielluiz ogabrielluiz changed the title feat: add way to pass callback through the Graph feat: add EventManager to centralize callbacks Aug 29, 2024
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from 8834512 to 3eba842 Compare August 29, 2024 11:41
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 29, 2024
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from 3eba842 to 1b94a21 Compare August 29, 2024 13:25
@ogabrielluiz ogabrielluiz marked this pull request as ready for review August 29, 2024 18:21
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Aug 29, 2024
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from bee1110 to 20cf69b Compare August 29, 2024 18:28
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 29, 2024
…date method call to on_log for better clarity and consistency
…oken for clarity and consistency in method naming
- Introduced `register_event_function` method to allow passing custom event functions.
- Updated `noop` method to accept `event_type` parameter.
- Adjusted `__getattr__` to return `EventCallback` type.
- Added tests for event registration, including default event type, empty string names, and specific event types.
- Added tests for custom event functions and unregistered event access.
- Added tests for event sending, including JSON formatting, empty data, and large payloads.
- Added tests for handling JSON serialization errors and the noop function.
- Introduced `_validate_event_function` method to ensure event functions are callable and have the correct parameters.
- Updated `register_event_function` to use the new validation method.
- Introduce `TestValidateEventFunction` class to test various scenarios for `_validate_event_function`.
- Add tests for valid event functions, non-callable event functions, invalid parameter counts, and parameter type validation.
- Include tests for handling unannotated parameters, flexible arguments, and keyword-only parameters.
- Ensure proper warnings and exceptions are raised for invalid event functions.
…n logic to enhance readability and maintainability

feat(event_manager.py): enforce event name conventions and improve callback handling for better error management
…yword arguments for better clarity and consistency

refactor(chat.py): extract message processing logic into separate methods for improved readability and maintainability
fix(chat.py): ensure proper handling of async iterators in message streaming
refactor(component.py): simplify event logging by removing unnecessary event name parameter in on_log method call
- Introduced `_validate_callback` method to ensure callbacks are callable and have the correct parameters.
- Updated `register_event` to include `manager` parameter in the callback.
…ger parameter for better context in event handling
@ogabrielluiz ogabrielluiz force-pushed the feat-add-way-to-pass-callback-through-the-Graph branch from 20cf69b to 2439eb3 Compare September 2, 2024 11:52
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 2, 2024
@nicoloboschi nicoloboschi merged commit 3eaad7b into main Sep 2, 2024
35 of 36 checks passed
@nicoloboschi nicoloboschi deleted the feat-add-way-to-pass-callback-through-the-Graph branch September 2, 2024 13:41
carlosrcoelho pushed a commit that referenced this pull request Sep 2, 2024
* refactor: Update MessageBase text attribute based on isinstance check.

* feat: Add update_message function to update a message in the database.

* refactor(chat): Update imports and remove unnecessary config method in ChatComponent.

* refactor: Add stream_message method to ChatComponent.

* refactor: Update method call in ChatOutput component.

* feat: Add callback function to custom component and update build_results signature.

* feat: Add callback parameter to instantiate_class function.

* feat(graph): Add callback functions for sync and async operations.

* feat: Add callback function support to vertex build process.

* feat: Add handling for added message in InterfaceVertex class.

* feat: Add callback support to Graph methods.

* feat(chat): Add callback function to build_vertices function.

* refactor: Simplify update_message function and use session_scope for session management.

* fix: Call set_callback method if available on custom component.

* refactor(chat): Update chat message chunk handling and ID conversion.

* feat: Add null check before setting cache in build_vertex_stream function.

* refactor: Fix send_event_wrapper function and add callback parameter to _build_vertex function.

* refactor: Simplify conditional statement and import order in ChatOutput.

* refactor: move log method to Component class.

* refactor: Simplify CallbackFunction definition.

* feat: Initialize _current_output attribute in Component class.

* feat: store current output name in custom component during processing.

* feat: Add current output and component ID to log data.

* fix: Add condition to check current output before invoking callback.

* refactor: Update callback to log_callback in graph methods.

* feat: Add test for callback graph execution with log messages.

* update projects

* fix(chat.py): fix condition to check if message text is a string before updating message text in the database

* refactor(ChatOutput.py): update ChatOutput class to correctly store and assign the message value to ensure consistency and avoid potential bugs

* refactor(chat.py): update return type of store_message method to return a single Message object instead of a list of Messages
refactor(chat.py): update logic to correctly handle updating and returning a single stored message object instead of a list of messages

* update starter projects

* refactor(component.py): update type hint for name parameter in log method to be more explicit

* feat: Add EventManager class for managing events and event registration

* refactor: Update log_callback to event_manager in custom component classes

* refactor(component.py): rename _log_callback to _event_manager and update method call to on_log for better clarity and consistency

* refactor(chat.py): rename _log_callback method to _event_manager.on_token for clarity and consistency in method naming

* refactor: Rename log_callback to event_manager for clarity and consistency

* refactor: Update Vertex class to use EventManager instead of log_callback for better clarity and consistency

* refactor: update build_flow to use EventManager

* refactor: Update EventManager class to use Protocol for event callbacks

* if event_type is not passed, it uses the default send_event

* Add method to register event functions in EventManager

- Introduced `register_event_function` method to allow passing custom event functions.
- Updated `noop` method to accept `event_type` parameter.
- Adjusted `__getattr__` to return `EventCallback` type.

* update test_callback_graph

* Add unit tests for EventManager in test_event_manager.py

- Added tests for event registration, including default event type, empty string names, and specific event types.
- Added tests for custom event functions and unregistered event access.
- Added tests for event sending, including JSON formatting, empty data, and large payloads.
- Added tests for handling JSON serialization errors and the noop function.

* revert chatOutput change

* Add validation for event function in EventManager

- Introduced `_validate_event_function` method to ensure event functions are callable and have the correct parameters.
- Updated `register_event_function` to use the new validation method.

* Add tests for EventManager's event function validation logic

- Introduce `TestValidateEventFunction` class to test various scenarios for `_validate_event_function`.
- Add tests for valid event functions, non-callable event functions, invalid parameter counts, and parameter type validation.
- Include tests for handling unannotated parameters, flexible arguments, and keyword-only parameters.
- Ensure proper warnings and exceptions are raised for invalid event functions.

* Add type ignore comment to lambda function in test_event_manager.py

* refactor: Update EventManager class to use Protocol for event callbacks

* refactor(event_manager.py): simplify event registration and validation logic to enhance readability and maintainability
feat(event_manager.py): enforce event name conventions and improve callback handling for better error management

* refactor(chat.py): standardize event_manager method calls by using keyword arguments for better clarity and consistency
refactor(chat.py): extract message processing logic into separate methods for improved readability and maintainability
fix(chat.py): ensure proper handling of async iterators in message streaming
refactor(component.py): simplify event logging by removing unnecessary event name parameter in on_log method call

* update event manager tests

* Add callback validation and manager parameter in EventManager

- Introduced `_validate_callback` method to ensure callbacks are callable and have the correct parameters.
- Updated `register_event` to include `manager` parameter in the callback.

* Add support for passing callback through the Graph in test_callback_graph

* fix(event_manager.py): update EventCallback signature to include manager parameter for better context in event handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants