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 possibility to initialize the Graph with components #3134

Merged
merged 118 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 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
86bba19
refactor: update BaseInputMixin to handle invalid field types gracefully
ogabrielluiz Jul 31, 2024
d495989
refactor: update file_types field alias in FileMixin
ogabrielluiz Jul 31, 2024
da58892
refactor(inputs): update field_type declarations in various input cla…
ogabrielluiz Jul 31, 2024
62c9ec4
refactor(inputs): convert dict to Message object in _validate_value m…
ogabrielluiz Jul 31, 2024
1d6491a
refactor(inputs): convert dict to Message object in _validate_value m…
ogabrielluiz Jul 31, 2024
5657101
refactor(inputs): update model_config in BaseInputMixin to enable pop…
ogabrielluiz Jul 31, 2024
1fe8126
refactor: update _extract_return_type method in CustomComponent to ac…
ogabrielluiz Jul 31, 2024
5ce27d2
refactor(component): add get_input and get_output methods for easier …
ogabrielluiz Jul 31, 2024
aab3fd6
refactor(vertex): add get_input and get_output methods for easier acc…
ogabrielluiz Jul 31, 2024
62acf55
refactor(component): add set_output_value method for easier modificat…
ogabrielluiz Jul 31, 2024
efd1592
feat: add run_until_complete and run_in_thread functions for handling…
ogabrielluiz Jul 31, 2024
fc54f35
refactor(component): add _edges attribute to Component class for mana…
ogabrielluiz Jul 31, 2024
1954edf
fix(component.py): fix conditional statement to check if self._vertex…
ogabrielluiz Jul 31, 2024
25b4dc5
refactor(component): add _get_fallback_input method for handling fall…
ogabrielluiz Jul 31, 2024
213a803
refactor(component): add TYPE_CHECKING import for Vertex in component.py
ogabrielluiz Jul 31, 2024
5ab8fed
refactor(component): add _map_parameters_on_frontend_node and _map_pa…
ogabrielluiz Jul 31, 2024
ea8ac9f
refactor(component): Add map_inputs and map_outputs methods for mappi…
ogabrielluiz Jul 31, 2024
13c63f0
refactor(component): Add Input, Output, and ComponentFrontendNode imp…
ogabrielluiz Jul 31, 2024
564af7e
refactor(component): Add map_inputs and map_outputs methods for mappi…
ogabrielluiz Jul 31, 2024
f324199
refactor(component): Add _process_connection_or_parameter method for …
ogabrielluiz Jul 31, 2024
e082ce6
refactor(frontend_node): Add set_field_value_in_template method for u…
ogabrielluiz Jul 31, 2024
8108555
refactor(inputs): Add DefaultPromptField class for default prompt inputs
ogabrielluiz Jul 31, 2024
3d76d6c
feat: Add Template.from_dict method for creating Template objects fro…
ogabrielluiz Jul 31, 2024
2452935
refactor(frontend_node): Add from_dict method for creating FrontendNo…
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
f1e03fa
refactor(graph): Add EdgeData import and update add_nodes_and_edges m…
ogabrielluiz Jul 31, 2024
939ae63
refactor(graph): Add first_layer property to Graph class
ogabrielluiz Jul 31, 2024
91276c6
refactor(graph): Update Graph class instantiation in base.py
ogabrielluiz Jul 31, 2024
805f9fe
refactor(graph): Add prepare method to Graph class
ogabrielluiz Jul 31, 2024
b706aea
refactor(graph): Improve graph preparation in retrieve_vertices_order…
ogabrielluiz Jul 31, 2024
4b04dd7
refactor: Add GetCache and SetCache protocols for caching functionality
ogabrielluiz Jul 31, 2024
2d9a641
refactor(graph): Add VertexBuildResult class for representing vertex …
ogabrielluiz Jul 31, 2024
edbbad1
refactor(chat.py, base.py): update build_vertex method in chat.py and…
ogabrielluiz Jul 31, 2024
92da504
refactor(graph): Update Edge and ContractEdge constructors to use Edg…
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
4b33c21
refactor(base): Update target_param assignment in Edge class
ogabrielluiz Jul 31, 2024
0de9b8b
refactor(base): Add check for existing type in add_types method
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
d3a3271
Merge branch 'refactor/edgetyping' into refactor/updateinputtypes
ogabrielluiz Jul 31, 2024
75f6a56
Merge branch 'refactor/updateinputtypes' into feat/addgetters
ogabrielluiz Jul 31, 2024
3201ce2
Merge branch 'feat/addgetters' into refactor/componentgraph
ogabrielluiz Jul 31, 2024
3aa7d0d
Merge branch 'refactor/componentgraph' into feat/tofrontendnode
ogabrielluiz Jul 31, 2024
ddd872e
Merge branch 'feat/tofrontendnode' into refactor/graph
ogabrielluiz Jul 31, 2024
dca6a8a
Merge branch 'refactor/graph' into refactor/buildvertextype
ogabrielluiz Jul 31, 2024
941bcc4
refactor(prompts): Update PromptComponent to support custom fields an…
ogabrielluiz Aug 1, 2024
9648ee4
refactor(base): Add DefaultPromptField to langflow.io
ogabrielluiz Aug 1, 2024
64573c9
refactor(prompts): Update PromptComponent to support custom fields an…
ogabrielluiz Aug 1, 2024
79ec97e
refactor(base): Update langflow.template.field.prompt.py for backward…
ogabrielluiz Aug 1, 2024
846ba0e
refactor(base): Update langflow.components.__init__.py to import the …
ogabrielluiz Aug 1, 2024
051a4c3
refactor(base): Update langflow.template.field.prompt.py for backward…
ogabrielluiz Aug 1, 2024
4a97dcc
refactor(graph): Update VertexTypesDict to import vertex types lazily
ogabrielluiz Aug 1, 2024
252ca15
refactor(graph): Add missing attributes and lock to Graph class
ogabrielluiz Aug 1, 2024
306ee86
refactor(graph): Add method to set inputs in Graph class
ogabrielluiz Aug 1, 2024
23d1546
refactor(graph): Set inputs for specific vertices in Graph class
ogabrielluiz Aug 1, 2024
d191d1c
refactor(graph): Update Graph class to set cache using flow_id
ogabrielluiz Aug 1, 2024
4d34a89
refactor(graph): Refactor Graph class to improve edge building
ogabrielluiz Aug 1, 2024
e0e4625
refactor(graph): Update _create_vertex method parameter name for clarity
ogabrielluiz Aug 1, 2024
46cd367
refactor(graph): Update Graph class to return first layer in sort_int…
ogabrielluiz Aug 1, 2024
1b900b2
refactor(graph): Update Graph class to use get_vertex method for buil…
ogabrielluiz Aug 1, 2024
9017a81
refactor(graph): Update Graph class to use astep method for asynchron…
ogabrielluiz Aug 1, 2024
c901a21
feat(base.py): implement methods to add components and component edge…
ogabrielluiz Aug 1, 2024
cd8dd2c
refactor(graph): Import nest_asyncio for asynchronous execution in Gr…
ogabrielluiz Aug 1, 2024
2514401
Merge branch 'refactor/buildvertextype' into feat/updatetemplate
ogabrielluiz Aug 1, 2024
bad3cbe
Merge branch 'feat/updatetemplate' into refactor/new-graph
ogabrielluiz Aug 1, 2024
2424bdc
refactor(base.py): Update Vertex class to handle parameter dictionari…
ogabrielluiz Aug 1, 2024
fbe5f3f
refactor(base.py): Add methods to set input values and add component …
ogabrielluiz Aug 1, 2024
800c759
refactor(message.py): Update _timestamp_to_str to handle datetime or …
ogabrielluiz Aug 1, 2024
c97b8c7
refactor(test_base.py): Add unit tests for Graph class
ogabrielluiz Aug 1, 2024
a08cfdd
refactor(initialize/loading.py): Refactor get_instance_results function
ogabrielluiz Aug 1, 2024
73a1d25
refactor(component.py): Add set_input_value method to Component class
ogabrielluiz Aug 1, 2024
cc23367
refactor(component.py): Set input value in _set_parameter_or_attribut…
ogabrielluiz Aug 1, 2024
9b5a761
refactor(inputs.py): Improve error message for invalid value type
ogabrielluiz Aug 1, 2024
7a002a4
feat: Add unit test for memory chatbot functionality
ogabrielluiz Aug 1, 2024
b821b22
refactor(base.py): Update __repr__ method in ContractEdge class
ogabrielluiz Aug 1, 2024
0f873ac
refactor(component.py): Update set method to return self
ogabrielluiz Aug 1, 2024
32452d0
refactor(starter_projects): Add unit test for vector store RAG
ogabrielluiz Aug 1, 2024
6467dfa
Merge branch 'main' into refactor/new-graph
ogabrielluiz Aug 5, 2024
39eae1b
refactor: remove unused prepare method in Graph class
ogabrielluiz Aug 5, 2024
a21dac2
refactor: update Output class to use list[str] for types field
ogabrielluiz Aug 5, 2024
7b6b629
refactor: add name validation to BaseInputMixin
ogabrielluiz Aug 5, 2024
1bebf86
refactor: update ContractEdge __repr__ method for improved readabilit…
ogabrielluiz Aug 5, 2024
3bd2b43
refactor: update BaseInputMixin to ensure name field is required with…
ogabrielluiz Aug 5, 2024
8691588
refactor: remove name validation from BaseInputMixin
ogabrielluiz Aug 5, 2024
b131d69
refactor: update input tests to include 'name' field in all input typ…
ogabrielluiz Aug 5, 2024
75b2a67
refactor: enhance Component class with methods to validate callable o…
ogabrielluiz Aug 5, 2024
73e02fc
refactor: disable load_from_db for inputs in Component class to impro…
ogabrielluiz Aug 5, 2024
5a7e46f
refactor: add test for setting invalid output in test_component.py
ogabrielluiz Aug 5, 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
30 changes: 28 additions & 2 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def set(self, **kwargs):
"""
for key, value in kwargs.items():
self._process_connection_or_parameter(key, value)
return self

def list_inputs(self):
"""
Expand Down Expand Up @@ -219,9 +220,32 @@ def _get_output_by_method(self, method: Callable):
raise ValueError(f"Output with method {method_name} not found")
return output

def _inherits_from_component(self, method: Callable):
# check if the method is a method from a class that inherits from Component
# and that it is an output of that class
inherits_from_component = hasattr(method, "__self__") and isinstance(method.__self__, Component)
return inherits_from_component

def _method_is_valid_output(self, method: Callable):
# check if the method is a method from a class that inherits from Component
# and that it is an output of that class
method_is_output = (
hasattr(method, "__self__")
and isinstance(method.__self__, Component)
and method.__self__._get_output_by_method(method)
)
return method_is_output

def _process_connection_or_parameter(self, key, value):
_input = self._get_or_create_input(key)
if callable(value):
# We need to check if callable AND if it is a method from a class that inherits from Component
if callable(value) and self._inherits_from_component(value):
try:
self._method_is_valid_output(value)
except ValueError:
raise ValueError(
f"Method {value.__name__} is not a valid output of {value.__self__.__class__.__name__}"
)
self._connect_to_component(key, value, _input)
else:
self._set_parameter_or_attribute(key, value)
Expand Down Expand Up @@ -264,6 +288,7 @@ def _add_edge(self, component, key, output, _input):
)

def _set_parameter_or_attribute(self, key, value):
self._set_input_value(key, value)
self._parameters[key] = value
self._attributes[key] = value

Expand Down Expand Up @@ -302,7 +327,8 @@ def _set_input_value(self, name: str, value: Any):
f"Input {name} is connected to {input_value.__self__.display_name}.{input_value.__name__}"
)
self._inputs[name].value = value
self._attributes[name] = value
if hasattr(self._inputs[name], "load_from_db"):
self._inputs[name].load_from_db = False
else:
raise ValueError(f"Input {name} not found in {self.__class__.__name__}")

Expand Down
4 changes: 4 additions & 0 deletions src/backend/base/langflow/graph/edge/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,8 @@ async def get_result_from_source(self, source: "Vertex", target: "Vertex"):
return self.result

def __repr__(self) -> str:
if (hasattr(self, "source_handle") and self.source_handle) and (
hasattr(self, "target_handle") and self.target_handle
):
return f"{self.source_id} -[{self.source_handle.name}->{self.target_handle.fieldName}]-> {self.target_id}"
return f"{self.source_id} -[{self.target_param}]-> {self.target_id}"
Loading
Loading