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 107 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: 9 additions & 21 deletions src/backend/base/langflow/api/v1/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,7 @@ async def retrieve_vertices_order(
graph = await build_and_cache_graph_from_data(
flow_id=flow_id_str, graph_data=data.model_dump(), chat_service=chat_service
)
graph.validate_stream()
if stop_component_id or start_component_id:
try:
first_layer = graph.sort_vertices(stop_component_id, start_component_id)
except Exception as exc:
logger.error(exc)
first_layer = graph.sort_vertices()
else:
first_layer = graph.sort_vertices()

for vertex_id in first_layer:
graph.run_manager.add_to_vertices_being_run(vertex_id)
graph = graph.prepare(stop_component_id, start_component_id)

# Now vertices is a list of lists
# We need to get the id of each vertex
Expand All @@ -122,7 +111,7 @@ async def retrieve_vertices_order(
playgroundSuccess=True,
),
)
return VerticesOrderResponse(ids=first_layer, run_id=graph._run_id, vertices_to_run=vertices_to_run)
return VerticesOrderResponse(ids=graph.first_layer, run_id=graph.run_id, vertices_to_run=vertices_to_run)
except Exception as exc:
background_tasks.add_task(
telemetry_service.log_package_playground,
Expand Down Expand Up @@ -189,19 +178,18 @@ async def build_vertex(

try:
lock = chat_service._async_cache_locks[flow_id_str]
(
result_dict,
params,
valid,
artifacts,
vertex,
) = await graph.build_vertex(
chat_service=chat_service,
vertex_build_result = await graph.build_vertex(
vertex_id=vertex_id,
user_id=current_user.id,
inputs_dict=inputs.model_dump() if inputs else {},
files=files,
get_cache=chat_service.get_cache,
set_cache=chat_service.set_cache,
)
result_dict = vertex_build_result.result_dict
params = vertex_build_result.params
valid = vertex_build_result.valid
artifacts = vertex_build_result.artifacts
next_runnable_vertices = await graph.get_next_runnable_vertices(lock, vertex=vertex, cache=False)
top_level_vertices = graph.get_top_level_vertices(next_runnable_vertices)

Expand Down
22 changes: 22 additions & 0 deletions src/backend/base/langflow/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
from . import (
agents,
chains,
documentloaders,
embeddings,
helpers,
inputs,
memories,
models,
outputs,
prompts,
prototypes,
retrievers,
textsplitters,
toolkits,
tools,
vectorstores,
)

__all__ = [
"agents",
"chains",
"documentloaders",
"embeddings",
"prompts",
"prototypes",
"models",
"helpers",
"inputs",
"memories",
"outputs",
Expand Down
17 changes: 17 additions & 0 deletions src/backend/base/langflow/components/prompts/Prompt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from langflow.base.prompts.api_utils import process_prompt_template
from langflow.custom import Component
from langflow.inputs.inputs import DefaultPromptField
from langflow.io import Output, PromptInput
from langflow.schema.message import Message
from langflow.template.utils import update_template_values
Expand Down Expand Up @@ -27,12 +28,25 @@ async def build_prompt(
self.status = prompt.text
return prompt

def _update_template(self, frontend_node: dict):
prompt_template = frontend_node["template"]["template"]["value"]
custom_fields = frontend_node["custom_fields"]
frontend_node_template = frontend_node["template"]
_ = process_prompt_template(
template=prompt_template,
name="template",
custom_fields=custom_fields,
frontend_node_template=frontend_node_template,
)
return frontend_node

def post_code_processing(self, new_frontend_node: dict, current_frontend_node: dict):
"""
This function is called after the code validation is done.
"""
frontend_node = super().post_code_processing(new_frontend_node, current_frontend_node)
template = frontend_node["template"]["template"]["value"]
# Kept it duplicated for backwards compatibility
_ = process_prompt_template(
template=template,
name="template",
Expand All @@ -43,3 +57,6 @@ def post_code_processing(self, new_frontend_node: dict, current_frontend_node: d
# and update the frontend_node with those values
update_template_values(new_template=frontend_node, previous_template=current_frontend_node["template"])
return frontend_node

def _get_fallback_input(self, **kwargs):
return DefaultPromptField(**kwargs)
Loading
Loading