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 support for cycles in graph #3295

Closed
wants to merge 54 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
76d112d
feat: Update Component class to store outputs in _outputs attribute
ogabrielluiz Aug 12, 2024
f028937
refactor: Remove unnecessary code setting outputs on custom component
ogabrielluiz Aug 12, 2024
d51ecbd
refactor(base): Remove redundant code in ContractEdge and Edge classes
ogabrielluiz Aug 12, 2024
0398952
feat: Add is_cycle attribute to Edge and ContractEdge classes
ogabrielluiz Aug 12, 2024
cdba12e
feat(graph): Add start component id in Graph prepare function
ogabrielluiz Aug 12, 2024
36b570d
refactor: Add logic to avoid duplicate nodes when getting successors
ogabrielluiz Aug 12, 2024
80cefff
feat: Add cycle detection functions to graph utils
ogabrielluiz Aug 12, 2024
8f4e308
feat: Add new client fixture to test_utils
ogabrielluiz Aug 12, 2024
5ebaee0
refactor: Add tests for detecting cycles in graphs
ogabrielluiz Aug 12, 2024
8b95827
feat: Add property to check if graph is cyclic
ogabrielluiz Aug 12, 2024
3b2a4ad
feat: Add cycles property to Graph class
ogabrielluiz Aug 12, 2024
97b5563
feat(graph): Update edge creation logic based on cycles in the graph.
ogabrielluiz Aug 12, 2024
cb9875f
feat: Improve handling of cycles in topological sort
ogabrielluiz Aug 12, 2024
4b4a258
refactor(base): Refactor get_all_successors method in Graph class to …
ogabrielluiz Aug 12, 2024
08a9a68
refactor: Implement _mark_branch method and modify mark_branch to uti…
ogabrielluiz Aug 12, 2024
aac0483
refactor(graph): Modify find_next_runnable_vertices method to use set…
ogabrielluiz Aug 12, 2024
c6be9b3
feat: Add method to retrieve value from template dict and set params …
ogabrielluiz Aug 12, 2024
88a97a5
refactor(vertex): Extract logic to set params from normal edge into h…
ogabrielluiz Aug 12, 2024
a51c436
refactor: Add check for flow_id before logging transaction calls in V…
ogabrielluiz Aug 12, 2024
ff265d6
feat: Improve error handling and logging in ComponentVertex class
ogabrielluiz Aug 12, 2024
fae0962
refactor: Get result from output if available in ComponentVertex
ogabrielluiz Aug 12, 2024
1a58fca
refactor!: Update default cache value to False in Output class
ogabrielluiz Aug 12, 2024
28a992b
feat: Add unit test for detecting cycles in graph
ogabrielluiz Aug 12, 2024
cfd48d6
refactor: Remove unnecessary retrieval of value in Component class
ogabrielluiz Aug 12, 2024
ac860fa
feat: Fix layered topological sort with cyclic graphs.
ogabrielluiz Aug 12, 2024
ae298e4
refactor: Handle missing keys when getting edge IDs.
ogabrielluiz Aug 12, 2024
7750ee6
fix: Update cache property to False in TestOutput class.
ogabrielluiz Aug 12, 2024
aa3f7fa
fix: Change cache value to false for various outputs in starter proje…
ogabrielluiz Aug 12, 2024
0ea3f1f
refactor: Update graph/base.py with new edge utility functions.
ogabrielluiz Aug 13, 2024
41cc917
merge main
ogabrielluiz Aug 13, 2024
02e873e
feat: Add state_model property to Graph class.
ogabrielluiz Aug 13, 2024
430bd2d
refactor: Add cyclic properties to Graph class.
ogabrielluiz Aug 13, 2024
62599ab
feat: Add method to set attributes on component output.
ogabrielluiz Aug 13, 2024
df36417
refactor: Refactor the logic for handling artifacts and logs generati…
ogabrielluiz Aug 13, 2024
f7efeea
refactor: Update set_output_value to set_on_output with cache parameter.
ogabrielluiz Aug 13, 2024
9ce01de
refactor(base): Remove unnecessary method call and update method call…
ogabrielluiz Aug 13, 2024
f06fe25
fix: Add in_degree_map to assertion message in test_memory_chatbot.
ogabrielluiz Aug 13, 2024
c115845
refactor: Remove self reference in in_degree_map operations.
ogabrielluiz Aug 13, 2024
3b04fd6
feat: Ensure all vertices have an in-degree value in Graph class.
ogabrielluiz Aug 13, 2024
226fba6
fix: Sort first layer before initializing run queue.
ogabrielluiz Aug 13, 2024
5f347c4
build: Update pytest-flakefinder to version 1.1.0 and add pytest-flak…
ogabrielluiz Aug 13, 2024
e289d8a
test: Update memory chatbot test with new assertions.
ogabrielluiz Aug 13, 2024
2ce3fe2
refactor: Enable caching for text output in starter projects.
ogabrielluiz Aug 13, 2024
36b1f65
Merged origin/main into feat: add support for cycles in graph
ogabrielluiz Aug 13, 2024
22c07e7
feat: Add should_continue method to check if iterations should continue.
ogabrielluiz Aug 13, 2024
a8a8d8e
feat: Add max_iterations to async_start and start methods.
ogabrielluiz Aug 13, 2024
00642cf
fix: self.stop only deactivates components after the caller
ogabrielluiz Aug 13, 2024
a7159ad
refactor: Increase max_iterations to 20 and add snapshots in graph un…
ogabrielluiz Aug 13, 2024
b9fad8f
test(graph): add test for cycle in graph with maximum iterations.
ogabrielluiz Aug 13, 2024
ff78520
refactor: Disable caching for text_output in multiple starter projects.
ogabrielluiz Aug 13, 2024
c7b623f
Merged origin/main into feat: add support for cycles in graph
ogabrielluiz Aug 13, 2024
bffac9b
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 13, 2024
963dd33
refactor: Improve type hinting in vertex and graph classes.
ogabrielluiz Aug 13, 2024
a1f013f
refactor: Change ContractEdge to CycleEdge in relevant classes.
ogabrielluiz Aug 13, 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: Refactor the logic for handling artifacts and logs generati…
…on in the component class.
  • Loading branch information
ogabrielluiz committed Aug 13, 2024
commit df364177661ec92e1e3a2db3901f95de3226cddc
55 changes: 28 additions & 27 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
@@ -555,6 +555,7 @@ async def _build_results(self):
method: Callable = getattr(self, output.method)
if output.cache and output.value != UNDEFINED:
_results[output.name] = output.value
result = output.value
else:
result = method()
# If the method is asynchronous, we need to await it
@@ -569,33 +570,33 @@ async def _build_results(self):
result.set_flow_id(self._vertex.graph.flow_id)
_results[output.name] = result
output.value = result
custom_repr = self.custom_repr()
if custom_repr is None and isinstance(result, (dict, Data, str)):
custom_repr = result
if not isinstance(custom_repr, str):
custom_repr = str(custom_repr)
raw = result
if self.status is None:
artifact_value = raw
else:
artifact_value = self.status
raw = self.status

if hasattr(raw, "data") and raw is not None:
raw = raw.data
if raw is None:
raw = custom_repr

elif hasattr(raw, "model_dump") and raw is not None:
raw = raw.model_dump()
if raw is None and isinstance(result, (dict, Data, str)):
raw = result.data if isinstance(result, Data) else result
artifact_type = get_artifact_type(artifact_value, result)
raw, artifact_type = post_process_raw(raw, artifact_type)
artifact = {"repr": custom_repr, "raw": raw, "type": artifact_type}
_artifacts[output.name] = artifact
self._output_logs[output.name] = self._logs
self._logs = []
custom_repr = self.custom_repr()
if custom_repr is None and isinstance(result, (dict, Data, str)):
custom_repr = result
if not isinstance(custom_repr, str):
custom_repr = str(custom_repr)
raw = result
if self.status is None:
artifact_value = raw
else:
artifact_value = self.status
raw = self.status

if hasattr(raw, "data") and raw is not None:
raw = raw.data
if raw is None:
raw = custom_repr

elif hasattr(raw, "model_dump") and raw is not None:
raw = raw.model_dump()
if raw is None and isinstance(result, (dict, Data, str)):
raw = result.data if isinstance(result, Data) else result
artifact_type = get_artifact_type(artifact_value, result)
raw, artifact_type = post_process_raw(raw, artifact_type)
artifact = {"repr": custom_repr, "raw": raw, "type": artifact_type}
_artifacts[output.name] = artifact
self._output_logs[output.name] = self._logs
self._logs = []
self._artifacts = _artifacts
self._results = _results
if self._tracing_service: