refactor: parameter name 'add_name' to 'keep_name' (#3116)
* refactor: update code references to use _code instead of code * refactor: add backwards compatible attributes to Component class * refactor: update Component constructor to pass config params with underscore Refactored the `Component` class in `component.py` to handle inputs and outputs. Added a new method `map_outputs` to map a list of outputs to the component. Also updated the `__init__` method to properly initialize the inputs, outputs, and other attributes. This change improves the flexibility and extensibility of the `Component` class. Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> * refactor: change attribute to use underscore * refactor: update CustomComponent initialization parameters Refactored the `instantiate_class` function in `loading.py` to update the initialization parameters for the `CustomComponent` class. Changed the parameter names from `user_id`, `parameters`, `vertex`, and `tracing_service` to `_user_id`, `_parameters`, `_vertex`, and `_tracing_service` respectively. This change ensures consistency and improves code readability. Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> * refactor: update BaseComponent to accept UUID for _user_id Updated the `BaseComponent` class in `base_component.py` to accept a `UUID` type for the `_user_id` attribute. This change improves the type safety and ensures consistency with the usage of `_user_id` throughout the codebase. * refactor: import nanoid with type annotation The `nanoid` import in `component.py` has been updated to include a type annotation `# type: ignore`. This change ensures that the type checker ignores any errors related to the `nanoid` import. * fix(custom_component.py): convert _user_id to string before passing to functions to ensure compatibility with function signatures * feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components * refactor: extract method to get method return type in CustomComponent * refactor(utils.py): refactor code to use _user_id instead of user_id for consistency and clarity perf(utils.py): optimize code by reusing cc_instance instead of calling get_component_instance multiple times * refactor(utils.py, base.py): change parameter name 'add_name' to 'keep_name' for clarity and consistency in codebase * [autofix.ci] apply automated fixes * refactor: update _extract_return_type method in CustomComponent to accept Any type The _extract_return_type method in CustomComponent has been updated to accept the Any type as the return_type parameter. This change improves the flexibility and compatibility of the method, allowing it to handle a wider range of return types. * refactor: update BaseComponent to use get_template_config method Refactored the `BaseComponent` class in `base_component.py` to use the `get_template_config` method instead of duplicating the code. This change improves code readability and reduces redundancy. * refactor: update build_custom_component_template to use add_name instead of keep_name Refactor the `build_custom_component_template` function in `utils.py` to use the `add_name` parameter instead of the deprecated `keep_name` parameter. This change ensures consistency with the updated method signature and improves code clarity. * feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components (#3115) * feat(component.py): add method to set output types based on method return type to improve type checking and validation in custom components * refactor: extract method to get method return type in CustomComponent * refactor: update _extract_return_type method in CustomComponent to accept Any type The _extract_return_type method in CustomComponent has been updated to accept the Any type as the return_type parameter. This change improves the flexibility and compatibility of the method, allowing it to handle a wider range of return types. * refactor: add _template_config property to BaseComponent Add a new `_template_config` property to the `BaseComponent` class in `base_component.py`. This property is used to store the template configuration for the custom component. If the `_template_config` property is empty, it is populated by calling the `build_template_config` method. This change improves the efficiency of accessing the template configuration and ensures that it is only built when needed. * refactor: add type checking for Output types in add_types method Improve type checking in the `add_types` method of the `Output` class in `base.py`. Check if the `type_` already exists in the `types` list before adding it. This change ensures that duplicate types are not added to the list. * update starter projects * refactor: optimize imports in base.py Optimize imports in the `base.py` file by removing unused imports and organizing the remaining imports. This change improves code readability and reduces unnecessary clutter. * fix(base.py): fix condition to check if self.types is not None before checking if type_ is in self.types * refactor: update build_custom_component_template to use add_name instead of keep_name --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
62191d92ae
commit
34bb9d9130
2 changed files with 6 additions and 6 deletions
|
|
@ -377,9 +377,9 @@ def build_custom_component_template_from_inputs(
|
|||
frontend_node.validate_component()
|
||||
# ! This should be removed when we have a better way to handle this
|
||||
frontend_node.set_base_classes_from_outputs()
|
||||
reorder_fields(frontend_node, cc_instance._get_field_order())
|
||||
|
||||
return frontend_node.to_dict(add_name=False), cc_instance
|
||||
reorder_fields(frontend_node, custom_component._get_field_order())
|
||||
cc_instance = get_component_instance(custom_component, user_id=user_id)
|
||||
return frontend_node.to_dict(keep_name=False), cc_instance
|
||||
|
||||
|
||||
def build_custom_component_template(
|
||||
|
|
@ -415,7 +415,7 @@ def build_custom_component_template(
|
|||
|
||||
reorder_fields(frontend_node, custom_instance._get_field_order())
|
||||
|
||||
return frontend_node.to_dict(add_name=False), custom_instance
|
||||
return frontend_node.to_dict(keep_name=False), custom_instance
|
||||
except Exception as exc:
|
||||
if isinstance(exc, HTTPException):
|
||||
raise exc
|
||||
|
|
|
|||
|
|
@ -90,10 +90,10 @@ class FrontendNode(BaseModel):
|
|||
return {name: result}
|
||||
|
||||
# For backwards compatibility
|
||||
def to_dict(self, add_name=True) -> dict:
|
||||
def to_dict(self, keep_name=True) -> dict:
|
||||
"""Returns a dict representation of the frontend node."""
|
||||
dump = self.model_dump(by_alias=True, exclude_none=True)
|
||||
if not add_name:
|
||||
if not keep_name:
|
||||
return dump.pop(self.name)
|
||||
return dump
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue