Merge branch 'python_custom_node_component' of github.com:logspace-ai/langflow into python_custom_node_component

This commit is contained in:
gustavoschaedler 2023-07-25 22:06:21 +01:00
commit 60f6c0a8ed
9 changed files with 32 additions and 60 deletions

View file

@ -147,10 +147,10 @@ class CustomComponent(Component, extra=Extra.allow):
raise ValueError(f"Flow {flow_id} not found")
return build_sorted_vertices_with_caching(data_graph)
def list_flow_names(self):
def list_flows(self):
with session_getter() as session:
flows = session.query(Flow).all()
return [flow.name for flow in flows]
return flows
def build(self):
raise NotImplementedError

View file

@ -18,9 +18,8 @@ from langflow.interface.custom.base import custom_component_creator
from langflow.interface.custom.custom_component import CustomComponent
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.tools import (
CustomComponentNode,
CustomComponentEmptyNode,
from langflow.template.frontend_node.custom_components import (
CustomComponentFrontendNode,
)
from langflow.interface.retrievers.base import retriever_creator
@ -165,7 +164,9 @@ def extract_type_from_optional(field_type):
def build_langchain_template_custom_component(custom_component: CustomComponent):
# Build base "CustomComponent" template
frontend_node = CustomComponentNode().to_dict().get(type(custom_component).__name__)
frontend_node = (
CustomComponentFrontendNode().to_dict().get(type(custom_component).__name__)
)
function_args = custom_component.get_function_entrypoint_args
return_type = custom_component.get_function_entrypoint_return_type

View file

@ -52,6 +52,7 @@ class FrontendNode(BaseModel):
custom_fields: defaultdict = defaultdict(list)
output_types: List[str] = []
field_formatters: FieldFormatters = Field(default_factory=FieldFormatters)
beta: bool = False
# field formatters is an instance attribute but it is not used in the class
# so we need to create a method to get it
@ -83,6 +84,7 @@ class FrontendNode(BaseModel):
"custom_fields": self.custom_fields,
"output_types": self.output_types,
"documentation": self.documentation,
"beta": self.beta,
},
}

View file

@ -7,6 +7,7 @@ from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE
class CustomComponentFrontendNode(FrontendNode):
name: str = "CustomComponent"
display_name: str = "Custom Component"
beta: bool = True
template: Template = Template(
type_name="CustomComponent",
fields=[

View file

@ -1,4 +1,3 @@
from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template
@ -141,53 +140,3 @@ class PythonFunctionNode(FrontendNode):
def to_dict(self):
return super().to_dict()
class CustomComponentNode(FrontendNode):
name: str = "CustomComponent"
template: Template = Template(
type_name="CustomComponent",
fields=[
TemplateField(
field_type="code",
required=True,
placeholder="",
is_list=False,
show=True,
value=DEFAULT_CUSTOM_COMPONENT_CODE,
name="code",
advanced=False,
dynamic=True,
)
],
)
description: str = "Dynamic Python code to be executed."
base_classes: list[str] = []
def to_dict(self):
return super().to_dict()
class CustomComponentEmptyNode(FrontendNode):
name: str = "CustomComponent"
template: Template = Template(
type_name="CustomComponent",
fields=[
TemplateField(
field_type="code",
required=True,
placeholder="",
is_list=False,
show=True,
value="",
name="code",
advanced=False,
dynamic=True,
)
],
)
description: str = "Dynamic Python code to be executed."
base_classes: list[str] = []
def to_dict(self):
return super().to_dict()