Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
05ca09e
refactor: Add utility functions for getting handle IDs in CustomNodes
ogabrielluiz Aug 5, 2024
373e280
refactor: Add type for escaped handle IDs in edges to improve type sa…
ogabrielluiz Aug 5, 2024
4271692
feat: Add function to escape handle IDs in edges, enhancing edge mana…
ogabrielluiz Aug 5, 2024
a179422
feat: Add function to check edges without escaped handle IDs, improvi…
ogabrielluiz Aug 5, 2024
f2f5c4e
feat: Enhance edge processing in reactflowUtils to handle edges witho…
ogabrielluiz Aug 5, 2024
b1504db
feat: Add layoutUtils module for handling node layout using elkjs
ogabrielluiz Aug 5, 2024
cd985c9
feat: update processDataFromFlow to add layout to nodes if needed
ogabrielluiz Aug 5, 2024
1c507d8
Refactor import paths to use 'initialize' module in 'base.py'
ogabrielluiz Aug 5, 2024
613a84f
feat: Add method to set class source code and integrate it with front…
ogabrielluiz Aug 5, 2024
5d24d7e
refactor: Update sourceHandle dataType to use custom component class …
ogabrielluiz Aug 5, 2024
59919cc
fix: Raise error for unknown vertex types instead of returning defaul…
ogabrielluiz Aug 5, 2024
06c8626
refactor: Remove redundant call to _import_vertex_types() in VertexTy…
ogabrielluiz Aug 5, 2024
280527a
refactor: Simplify add_code_field by removing unnecessary field_confi…
ogabrielluiz Aug 5, 2024
e46ebbc
feat: Add elkjs dependency to package.json and package-lock.json for …
ogabrielluiz Aug 5, 2024
269f46b
refactor: Update fields type in Template class to use InputTypes for …
ogabrielluiz Aug 5, 2024
3691fbd
refactor: Reorganize imports in __init__.py for better structure and …
ogabrielluiz Aug 5, 2024
1e3be3f
refactor: Clean up imports in types.py for better organization and co…
ogabrielluiz Aug 5, 2024
bb6b331
refactor: Change vertex type annotations to strings for better compat…
ogabrielluiz Aug 5, 2024
1a287c1
refactor: Update component instantiation to include _code parameter a…
ogabrielluiz Aug 5, 2024
b3bcfa3
refactor: Remove unused CustomComponent import from __init__.py for c…
ogabrielluiz Aug 5, 2024
f465f27
refactor: Modify custom_component instantiation to include _code argu…
ogabrielluiz Aug 5, 2024
6d185c5
refactor: Update CustomComponent import in __init__.py for improved m…
ogabrielluiz Aug 5, 2024
6897ec8
refactor: Update launch.json to include correct path for backend sour…
ogabrielluiz Aug 5, 2024
5d1ef23
refactor: Update dependencies in poetry.lock to latest versions and r…
ogabrielluiz Aug 5, 2024
312945c
refactor: Update dataType assignment in Component class to use compon…
ogabrielluiz Aug 6, 2024
47a03e4
refactor: Correct flow_id reference in MemoryComponent to improve cla…
ogabrielluiz Aug 6, 2024
5e41abe
refactor: Update import path for DefaultPromptField to improve code o…
ogabrielluiz Aug 6, 2024
6178058
refactor: Add loading module to __init__.py for improved organization…
ogabrielluiz Aug 6, 2024
36cabbf
refactor: Clean up imports in base.py and enforce edge validation in …
ogabrielluiz Aug 6, 2024
0586682
refactor: Remove edge component additions in test_base.py to streamli…
ogabrielluiz Aug 6, 2024
25b080e
refactor: Mark @clack/prompts is-unicode-supported as extraneous in p…
ogabrielluiz Aug 6, 2024
07de10c
refactor: Update dataType assignment in Component class to use compon…
ogabrielluiz Aug 6, 2024
25046ab
refactor: Fix edge existence check in Graph class to use correct vari…
ogabrielluiz Aug 6, 2024
bdfb3d8
refactor: Add test for graph with edge and improve graph preparation …
ogabrielluiz Aug 6, 2024
4457775
refactor: Set default node type to "genericNode" in getLayoutedNodes …
ogabrielluiz Aug 6, 2024
02707e9
create consts for node widht and height
anovazzi1 Aug 6, 2024
906e687
refactor: Catch and log errors when processing flow data in flowsMana…
anovazzi1 Aug 6, 2024
5b5dc24
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 6, 2024
5df5af9
fix: Validate custom components for source and target vertices in Gra…
ogabrielluiz Aug 6, 2024
8099f92
test: Add fixture for client and raise TypeError for invalid class pa…
ogabrielluiz Aug 6, 2024
684af41
test: Add unit test for listing flows as Flow objects in custom compo…
ogabrielluiz Aug 6, 2024
b17b29f
test: Update assertions for memory chatbot component types in unit tests
ogabrielluiz Aug 6, 2024
a0b6916
test: Refactor assertions to use updated component names in vector st…
ogabrielluiz Aug 6, 2024
8f0789a
fix: Change error handling to return default Vertex for unknown node …
ogabrielluiz Aug 6, 2024
617f15b
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 6, 2024
a2bf7e4
test: Add pytest fixture for CustomComponent in unit tests to enhance…
ogabrielluiz Aug 6, 2024
969a857
chore: Update component names in vector store RAG unit tests
ogabrielluiz Aug 6, 2024
9ed053e
test: Refactor imports and make flow name generation unique in databa…
ogabrielluiz Aug 6, 2024
473de91
chore: Remove unused upload and flow management functions from flowsM…
ogabrielluiz Aug 7, 2024
fa8c44e
chore: Await processDataFromFlow in useAddFlow hook
ogabrielluiz Aug 7, 2024
496e7a3
chore: Correct NODE_HEIGHT calculation to use NODE_WIDTH constant for…
ogabrielluiz Aug 7, 2024
7d12ea0
chore: Remove extraneous flag for is-unicode-supported in package-loc…
ogabrielluiz Aug 7, 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
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Debug Backend",
"type": "debugpy",
Expand All @@ -18,7 +17,7 @@
"--loop",
"asyncio",
"--reload-include",
"src/backend/*"
"./src/backend/*"
],
"jinja": true,
"justMyCode": false,
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/backend/base/langflow/components/helpers/Memory.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from langchain.memory import ConversationBufferMemory

from langflow.custom import Component
from langflow.field_typing import BaseChatMemory
from langflow.helpers.data import data_to_text
from langflow.inputs import HandleInput
from langflow.io import DropdownInput, IntInput, MessageTextInput, MultilineInput, Output
from langflow.memory import get_messages, LCBuiltinChatMemory
from langflow.memory import LCBuiltinChatMemory, get_messages
from langflow.schema import Data
from langflow.schema.message import Message
from langflow.field_typing import BaseChatMemory
from langchain.memory import ConversationBufferMemory

from langflow.utils.constants import MESSAGE_SENDER_AI, MESSAGE_SENDER_USER


Expand Down Expand Up @@ -118,5 +118,5 @@ def build_lc_memory(self) -> BaseChatMemory:
if self.memory:
chat_memory = self.memory
else:
chat_memory = LCBuiltinChatMemory(flow_id=self.graph.flow_id, session_id=self.session_id)
chat_memory = LCBuiltinChatMemory(flow_id=self.flow_id, session_id=self.session_id)
return ConversationBufferMemory(chat_memory=chat_memory)
2 changes: 1 addition & 1 deletion src/backend/base/langflow/custom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from langflow.custom.custom_component import CustomComponent
from langflow.custom.custom_component.component import Component
from langflow.custom.custom_component.custom_component import CustomComponent

__all__ = ["CustomComponent", "Component"]
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def parse_global_vars(self, node: ast.Assign) -> None:

def execute_and_inspect_classes(self, code: str):
custom_component_class = eval_custom_component_code(code)
custom_component = custom_component_class()
custom_component = custom_component_class(_code=code)
dunder_class = custom_component.__class__
# Get the base classes at two levels of inheritance
bases = []
Expand Down
3 changes: 0 additions & 3 deletions src/backend/base/langflow/custom/custom_component/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .custom_component import CustomComponent

__all__ = ["CustomComponent"]
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def build_template_config(self) -> dict:
return {}

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

Expand Down
43 changes: 36 additions & 7 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import yaml
from pydantic import BaseModel

from langflow.graph.edge.schema import EdgeData
from langflow.helpers.custom import format_type
from langflow.inputs.inputs import InputTypes
from langflow.schema.artifact import get_artifact_type, post_process_raw
from langflow.schema.data import Data
from langflow.schema.message import Message
Expand All @@ -20,13 +18,15 @@
from .custom_component import CustomComponent

if TYPE_CHECKING:
from langflow.graph.edge.schema import EdgeData
from langflow.graph.vertex.base import Vertex
from langflow.inputs.inputs import InputTypes

BACKWARDS_COMPATIBLE_ATTRIBUTES = ["user_id", "vertex", "tracing_service"]


class Component(CustomComponent):
inputs: List[InputTypes] = []
inputs: List["InputTypes"] = []
outputs: List[Output] = []
code_class_base_inheritance: ClassVar[str] = "Component"
_output_logs: dict[str, Log] = {}
Expand All @@ -41,7 +41,7 @@ def __init__(self, **kwargs):
config[key] = value
else:
inputs[key] = value
self._inputs: dict[str, InputTypes] = {}
self._inputs: dict[str, "InputTypes"] = {}
self._outputs: dict[str, Output] = {}
self._results: dict[str, Any] = {}
self._attributes: dict[str, Any] = {}
Expand All @@ -64,6 +64,20 @@ def __init__(self, **kwargs):
self.map_outputs(self.outputs)
# Set output types
self._set_output_types()
self.set_class_code()

def set_class_code(self):
# Get the source code of the calling class
if self._code:
return
try:
module = inspect.getmodule(self.__class__)
if module is None:
raise ValueError("Could not find module for class")
class_code = inspect.getsource(module)
self._code = class_code
except OSError:
raise ValueError(f"Could not find source code for {self.__class__.__name__}")

def set(self, **kwargs):
"""
Expand Down Expand Up @@ -174,7 +188,7 @@ def map_outputs(self, outputs: List[Output]):
raise ValueError("Output name cannot be None.")
self._outputs[output.name] = output

def map_inputs(self, inputs: List[InputTypes]):
def map_inputs(self, inputs: List["InputTypes"]):
"""
Maps the given inputs to the component.

Expand Down Expand Up @@ -272,7 +286,7 @@ def _add_edge(self, component, key, output, _input):
"target": self._id,
"data": {
"sourceHandle": {
"dataType": self.name,
"dataType": component.name or component.__class__.__name__,
"id": component._id,
"name": output.name,
"output_types": output.types,
Expand Down Expand Up @@ -366,6 +380,21 @@ def to_frontend_node(self):
self._map_parameters_on_template(frontend_node_dict["template"])

frontend_node = ComponentFrontendNode.from_dict(frontend_node_dict)
if not self._code:
self.set_class_code()
code_field = Input(
dynamic=True,
required=True,
placeholder="",
multiline=True,
value=self._code,
password=False,
name="code",
advanced=True,
field_type="code",
is_list=False,
)
frontend_node.template.add_field(code_field)

for output in frontend_node.outputs:
if output.types:
Expand All @@ -379,7 +408,7 @@ def to_frontend_node(self):
data = {
"data": {
"node": frontend_node.to_dict(keep_name=False),
"type": self.__class__.__name__,
"type": self.name or self.__class__.__name__,
}
}
return data
Expand Down
8 changes: 4 additions & 4 deletions src/backend/base/langflow/custom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_component_instance(custom_component: CustomComponent, user_id: Optional[
) from exc

try:
custom_instance = custom_class(_user_id=user_id)
custom_instance = custom_class(_user_id=user_id, _code=custom_component._code)
return custom_instance
except Exception as exc:
logger.error(f"Error while instantiating custom component: {str(exc)}")
Expand Down Expand Up @@ -339,7 +339,7 @@ def run_build_config(
raise exc


def add_code_field(frontend_node: CustomComponentFrontendNode, raw_code, field_config):
def add_code_field(frontend_node: CustomComponentFrontendNode, raw_code):
code_field = Input(
dynamic=True,
required=True,
Expand All @@ -364,7 +364,7 @@ def build_custom_component_template_from_inputs(
cc_instance = get_component_instance(custom_component, user_id=user_id)
field_config = cc_instance.get_template_config(cc_instance)
frontend_node = ComponentFrontendNode.from_inputs(**field_config)
frontend_node = add_code_field(frontend_node, custom_component._code, field_config.get("code", {}))
frontend_node = add_code_field(frontend_node, custom_component._code)
# But we now need to calculate the return_type of the methods in the outputs
for output in frontend_node.outputs:
if output.types:
Expand Down Expand Up @@ -408,7 +408,7 @@ def build_custom_component_template(

add_extra_fields(frontend_node, field_config, entrypoint_args)

frontend_node = add_code_field(frontend_node, custom_component._code, field_config.get("code", {}))
frontend_node = add_code_field(frontend_node, custom_component._code)

add_base_classes(frontend_node, custom_component.get_function_entrypoint_return_type)
add_output_types(frontend_node, custom_component.get_function_entrypoint_return_type)
Expand Down
Loading