-
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 dynamic outputs to Component #4308
Conversation
fe3154a
to
7b342f4
Compare
fe09438
to
ac759a2
Compare
This commit refactors the Component class in the `component.py` file. It introduces two new methods: `update_inputs` and `run_and_validate_update_outputs`. The `update_inputs` method allows for updating the build configuration with new field values, while the `run_and_validate_update_outputs` method updates the frontend node and validates the outputs. Additionally, the `_validate_frontend_node` method is added to check if all outputs are valid. The `_set_output_types` method is modified to accept a list of outputs and set their return types. Overall, these changes improve the functionality and maintainability of the Component class.
ac759a2
to
ab42efb
Compare
Earlier frontend_node was used to update the inputs and later we moved to build_config. In the same way, should we utilize build_config instead of frontend_node so the DX would be much better? |
They serve different purposes. We could put them in a single method but I think that would make it confusing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Good Work. May be we can improve the experience later. But this is going to be awesome start.
…dant test_get_sidebar_components
* Refine condition to check for undefined value in use-handle-new-value hook * update mutateTemplate to use APIClassType * Refactor Component class to update inputs and validate outputs This commit refactors the Component class in the `component.py` file. It introduces two new methods: `update_inputs` and `run_and_validate_update_outputs`. The `update_inputs` method allows for updating the build configuration with new field values, while the `run_and_validate_update_outputs` method updates the frontend node and validates the outputs. Additionally, the `_validate_frontend_node` method is added to check if all outputs are valid. The `_set_output_types` method is modified to accept a list of outputs and set their return types. Overall, these changes improve the functionality and maintainability of the Component class. * Add dynamic output validation in API endpoint for component updates * Update build_config to store field_value under "value" key * Refactor: Convert dict values to list in _set_output_types call * Add type check for `cc_instance` before calling `run_and_validate_update_outputs` * Add DynamicOutputComponent with configurable outputs based on input * Add test for updating component outputs with dynamic code input * Refactor: Make get_dynamic_output_component_code asynchronous for improved performance --------- Co-authored-by: Edwin Jose <[email protected]>
This pull request includes several changes to improve the backend and frontend functionality of the Langflow project. The most important changes include updates to the custom component handling, validation improvements, and modifications to the frontend data fetching and mutation logic.
Backend Improvements:
src/backend/base/langflow/api/v1/endpoints.py
: Refactored imports to a single line for better readability and added logic to update component templates and validate outputs during custom component updates. [1] [2]src/backend/base/langflow/custom/custom_component/component.py
: Added validation for frontend node outputs and new methods for updating inputs and outputs. [1] [2] [3] [4]src/backend/tests/data/dynamic_output_component.py
: Introduced a newDynamicOutputComponent
class to serve as a template for creating custom components.src/backend/tests/unit/api/v1/test_endpoints.py
: Added a test case for updating component outputs to ensure the new functionality works as expected. [1] [2]Frontend Improvements:
src/frontend/src/CustomNodes/helpers/mutate-template.ts
: Updated themutateTemplate
function to handle new template and output structures. [1] [2] [3]src/frontend/src/CustomNodes/hooks/use-fetch-data-on-mount.tsx
: Modified import statements and updated the type forpostTemplateValue
toAPIClassType
. [1] [2]src/frontend/src/CustomNodes/hooks/use-handle-new-value.tsx
: Changed the condition to check forundefined
values in theuseHandleOnNewValue
hook.src/frontend/src/controllers/API/queries/nodes/use-post-template-value.ts
: Updated the mutation function to returnAPIClassType
instead ofAPITemplateType
and adjusted the response handling accordingly. [1] [2] [3]