-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
nicoloboschi
merged 55 commits into
main
from
feat-add-way-to-pass-callback-through-the-Graph
Sep 2, 2024
Merged
feat: add EventManager to centralize callbacks #3434
nicoloboschi
merged 55 commits into
main
from
feat-add-way-to-pass-callback-through-the-Graph
Sep 2, 2024
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
Pull Request Validation ReportThis comment is automatically generated by Conventional PR Whitelist Report
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 |
This pull request is automatically being deployed by Amplify Hosting (learn more). |
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
August 19, 2024 20:34
b90a1d2
to
b8ad9eb
Compare
github-actions
bot
added
enhancement
New feature or request
and removed
enhancement
New feature or request
labels
Aug 20, 2024
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
4 times, most recently
from
August 23, 2024 20:38
3946f9f
to
ec4aa65
Compare
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
August 28, 2024 19:39
5efc982
to
1db1b0e
Compare
ogabrielluiz
changed the title
feat: add way to pass callback through the Graph
feat: add EventManager to centralize callbacks
Aug 29, 2024
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
August 29, 2024 11:41
8834512
to
3eba842
Compare
github-actions
bot
added
enhancement
New feature or request
and removed
enhancement
New feature or request
labels
Aug 29, 2024
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
August 29, 2024 13:25
3eba842
to
1b94a21
Compare
dosubot
bot
added
the
size:XL
This PR changes 500-999 lines, ignoring generated files.
label
Aug 29, 2024
ogabrielluiz
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
August 29, 2024 18:28
bee1110
to
20cf69b
Compare
github-actions
bot
added
enhancement
New feature or request
and removed
enhancement
New feature or request
labels
Aug 29, 2024
…thod to be more explicit
…date method call to on_log for better clarity and consistency
…oken for clarity and consistency in method naming
…back for better clarity and consistency
- 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
force-pushed
the
feat-add-way-to-pass-callback-through-the-Graph
branch
from
September 2, 2024 11:52
20cf69b
to
2439eb3
Compare
nicoloboschi
approved these changes
Sep 2, 2024
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.
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.
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.