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

refactor: update schema.py to include Edge related types #3117

Merged
merged 35 commits into from
Aug 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
58c4369
refactor: update code references to use _code instead of code
ogabrielluiz Jul 31, 2024
1f96feb
refactor: add backwards compatible attributes to Component class
ogabrielluiz Jul 31, 2024
290f685
refactor: update Component constructor to pass config params with und…
ogabrielluiz Jul 31, 2024
ca1aa32
refactor: change attribute to use underscore
ogabrielluiz Jul 31, 2024
81391c5
refactor: update CustomComponent initialization parameters
ogabrielluiz Jul 31, 2024
6d01eda
refactor: update BaseComponent to accept UUID for _user_id
ogabrielluiz Jul 31, 2024
49349ff
refactor: import nanoid with type annotation
ogabrielluiz Jul 31, 2024
1e2f517
fix(custom_component.py): convert _user_id to string before passing t…
ogabrielluiz Jul 31, 2024
fde9687
feat(component.py): add method to set output types based on method re…
ogabrielluiz Jul 31, 2024
7f679a4
refactor: extract method to get method return type in CustomComponent
ogabrielluiz Jul 31, 2024
485e5e2
refactor(utils.py): refactor code to use _user_id instead of user_id …
ogabrielluiz Jul 31, 2024
2c389dc
refactor(utils.py, base.py): change parameter name 'add_name' to 'kee…
ogabrielluiz Jul 31, 2024
5325541
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 31, 2024
4a455db
refactor: update schema.py to include Edge related typres
ogabrielluiz Jul 31, 2024
1fe8126
refactor: update _extract_return_type method in CustomComponent to ac…
ogabrielluiz Jul 31, 2024
6ab4c35
refactor: update BaseComponent to use get_template_config method
ogabrielluiz Jul 31, 2024
f5d5ee8
Merge branch 'main' into refactor/initconfig
ogabrielluiz Jul 31, 2024
64d6190
Merge branch 'refactor/initconfig' into feat/outputtypes
ogabrielluiz Jul 31, 2024
97f14ef
Merge branch 'feat/outputtypes' into refactor/renamefnode
ogabrielluiz Jul 31, 2024
397893c
feat: add BaseModel class with model_config attribute
ogabrielluiz Jul 31, 2024
b59a6cc
refactor: update langflow.graph.edge.schema.py
ogabrielluiz Jul 31, 2024
8cc7700
refactor: update build_custom_component_template to use add_name inst…
ogabrielluiz Jul 31, 2024
c4de2b7
Merge branch 'main' into refactor/initconfig
ogabrielluiz Jul 31, 2024
a88ff42
feat(component.py): add method to set output types based on method re…
ogabrielluiz Jul 31, 2024
a8c3564
refactor: add _template_config property to BaseComponent
ogabrielluiz Jul 31, 2024
1ed4812
refactor: add type checking for Output types in add_types method
ogabrielluiz Jul 31, 2024
7acc1dd
update starter projects
ogabrielluiz Jul 31, 2024
4be549f
refactor: optimize imports in base.py
ogabrielluiz Jul 31, 2024
61bdbb1
fix(base.py): fix condition to check if self.types is not None before…
ogabrielluiz Jul 31, 2024
06ea280
Merge branch 'refactor/initconfig' into refactor/renamefnode
ogabrielluiz Jul 31, 2024
f9deeb6
Merge branch 'main' into refactor/renamefnode
ogabrielluiz Jul 31, 2024
e43ead1
Merge branch 'refactor/renamefnode' into refactor/edgetyping
ogabrielluiz Jul 31, 2024
cb4bb93
refactor: update build_custom_component_template to use add_name inst…
ogabrielluiz Jul 31, 2024
e9f082c
Merge branch 'refactor/renamefnode' into refactor/edgetyping
ogabrielluiz Jul 31, 2024
a235083
Merge branch 'main' into refactor/edgetyping
ogabrielluiz Jul 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
ogabrielluiz committed Jul 31, 2024
commit 6ab4c35e50bbc4bb33833eeba7b9d78049bcfb7a
36 changes: 22 additions & 14 deletions src/backend/base/langflow/custom/custom_component/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseComponent:
"""The code of the component. Defaults to None."""
_function_entrypoint_name: str = "build"
field_config: dict = {}
_user_id: Optional[str | UUID]
_user_id: Optional[str | UUID] = None

def __init__(self, **data):
self.cache = TTLCache(maxsize=1024, ttl=60)
Expand All @@ -39,7 +39,7 @@ def __init__(self, **data):
setattr(self, key, value)

def __setattr__(self, key, value):
if key == "_user_id" and hasattr(self, "_user_id"):
if key == "_user_id" and hasattr(self, "_user_id") and getattr(self, "_user_id") is not None:
warnings.warn("user_id is immutable and cannot be changed.")
super().__setattr__(key, value)

Expand All @@ -66,23 +66,16 @@ def get_function(self):

return validate.create_function(self._code, self._function_entrypoint_name)

def build_template_config(self) -> dict:
@staticmethod
def get_template_config(component):
"""
Builds the template configuration for the custom component.

Returns:
A dictionary representing the template configuration.
Gets the template configuration for the custom component itself.
"""
if not self._code:
return {}

cc_class = eval_custom_component_code(self._code)
component_instance = cc_class()
template_config = {}

for attribute, func in ATTR_FUNC_MAPPING.items():
if hasattr(component_instance, attribute):
value = getattr(component_instance, attribute)
if hasattr(component, attribute):
value = getattr(component, attribute)
if value is not None:
template_config[attribute] = func(value=value)

Expand All @@ -92,5 +85,20 @@ def build_template_config(self) -> dict:

return template_config

def build_template_config(self) -> dict:
"""
Builds the template configuration for the custom component.

Returns:
A dictionary representing the template configuration.
"""
if not self._code:
return {}

cc_class = eval_custom_component_code(self._code)
component_instance = cc_class()
template_config = self.get_template_config(component_instance)
return template_config

def build(self, *args: Any, **kwargs: Any) -> Any:
raise NotImplementedError