Merge branch 'python_custom_node_component' of github.com:logspace-ai/langflow into python_custom_node_component
This commit is contained in:
commit
60f6c0a8ed
9 changed files with 32 additions and 60 deletions
|
|
@ -147,10 +147,10 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
raise ValueError(f"Flow {flow_id} not found")
|
raise ValueError(f"Flow {flow_id} not found")
|
||||||
return build_sorted_vertices_with_caching(data_graph)
|
return build_sorted_vertices_with_caching(data_graph)
|
||||||
|
|
||||||
def list_flow_names(self):
|
def list_flows(self):
|
||||||
with session_getter() as session:
|
with session_getter() as session:
|
||||||
flows = session.query(Flow).all()
|
flows = session.query(Flow).all()
|
||||||
return [flow.name for flow in flows]
|
return flows
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,8 @@ from langflow.interface.custom.base import custom_component_creator
|
||||||
from langflow.interface.custom.custom_component import CustomComponent
|
from langflow.interface.custom.custom_component import CustomComponent
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.tools import (
|
from langflow.template.frontend_node.custom_components import (
|
||||||
CustomComponentNode,
|
CustomComponentFrontendNode,
|
||||||
CustomComponentEmptyNode,
|
|
||||||
)
|
)
|
||||||
from langflow.interface.retrievers.base import retriever_creator
|
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):
|
def build_langchain_template_custom_component(custom_component: CustomComponent):
|
||||||
# Build base "CustomComponent" template
|
# 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
|
function_args = custom_component.get_function_entrypoint_args
|
||||||
return_type = custom_component.get_function_entrypoint_return_type
|
return_type = custom_component.get_function_entrypoint_return_type
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ class FrontendNode(BaseModel):
|
||||||
custom_fields: defaultdict = defaultdict(list)
|
custom_fields: defaultdict = defaultdict(list)
|
||||||
output_types: List[str] = []
|
output_types: List[str] = []
|
||||||
field_formatters: FieldFormatters = Field(default_factory=FieldFormatters)
|
field_formatters: FieldFormatters = Field(default_factory=FieldFormatters)
|
||||||
|
beta: bool = False
|
||||||
|
|
||||||
# field formatters is an instance attribute but it is not used in the class
|
# field formatters is an instance attribute but it is not used in the class
|
||||||
# so we need to create a method to get it
|
# so we need to create a method to get it
|
||||||
|
|
@ -83,6 +84,7 @@ class FrontendNode(BaseModel):
|
||||||
"custom_fields": self.custom_fields,
|
"custom_fields": self.custom_fields,
|
||||||
"output_types": self.output_types,
|
"output_types": self.output_types,
|
||||||
"documentation": self.documentation,
|
"documentation": self.documentation,
|
||||||
|
"beta": self.beta,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE
|
||||||
class CustomComponentFrontendNode(FrontendNode):
|
class CustomComponentFrontendNode(FrontendNode):
|
||||||
name: str = "CustomComponent"
|
name: str = "CustomComponent"
|
||||||
display_name: str = "Custom Component"
|
display_name: str = "Custom Component"
|
||||||
|
beta: bool = True
|
||||||
template: Template = Template(
|
template: Template = Template(
|
||||||
type_name="CustomComponent",
|
type_name="CustomComponent",
|
||||||
fields=[
|
fields=[
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.base import FrontendNode
|
from langflow.template.frontend_node.base import FrontendNode
|
||||||
from langflow.template.template.base import Template
|
from langflow.template.template.base import Template
|
||||||
|
|
@ -141,53 +140,3 @@ class PythonFunctionNode(FrontendNode):
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return super().to_dict()
|
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()
|
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ export default function GenericNode({
|
||||||
"generic-node-div"
|
"generic-node-div"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
{data.node.beta && (
|
||||||
|
<div className="beta-badge-wrapper">
|
||||||
|
<div className="beta-badge-content">BETA</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="generic-node-div-title">
|
<div className="generic-node-div-title">
|
||||||
<div className="generic-node-title-arrangement">
|
<div className="generic-node-title-arrangement">
|
||||||
<IconComponent
|
<IconComponent
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@
|
||||||
--chat-bot-icon: #afe6ef;
|
--chat-bot-icon: #afe6ef;
|
||||||
--chat-user-icon: #aface9;
|
--chat-user-icon: #aface9;
|
||||||
|
|
||||||
|
--beta-background: rgb(219 234 254);
|
||||||
|
--beta-foreground: rgb(37 99 235);
|
||||||
|
|
||||||
/* Colors that are shared in dark and light mode */
|
/* Colors that are shared in dark and light mode */
|
||||||
--blur-shared: #151923de;
|
--blur-shared: #151923de;
|
||||||
--build-trigger: #dc735b;
|
--build-trigger: #dc735b;
|
||||||
|
|
@ -101,6 +104,9 @@
|
||||||
--high-indigo: #4338ca;
|
--high-indigo: #4338ca;
|
||||||
--medium-indigo: #6366f1;
|
--medium-indigo: #6366f1;
|
||||||
|
|
||||||
|
--beta-background: rgb(37 99 235);
|
||||||
|
--beta-foreground: rgb(219 234 254);
|
||||||
|
|
||||||
/* Colors that are shared in dark and light mode */
|
/* Colors that are shared in dark and light mode */
|
||||||
--blur-shared: #151923d2;
|
--blur-shared: #151923d2;
|
||||||
--build-trigger: #dc735b;
|
--build-trigger: #dc735b;
|
||||||
|
|
@ -369,7 +375,7 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
}
|
}
|
||||||
|
|
||||||
.generic-node-status-position {
|
.generic-node-status-position {
|
||||||
@apply relative top-[3px] h-5 w-5;
|
@apply relative top-[1.5px] h-5 w-5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.generic-node-status-animation {
|
.generic-node-status-animation {
|
||||||
|
|
@ -1111,7 +1117,12 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
.ace-editor-save-btn {
|
.ace-editor-save-btn {
|
||||||
@apply flex-max-width h-fit justify-end;
|
@apply flex-max-width h-fit justify-end;
|
||||||
}
|
}
|
||||||
|
.beta-badge-wrapper {
|
||||||
|
@apply absolute right-0 top-0 h-16 w-16 overflow-hidden rounded-tr-lg;
|
||||||
|
}
|
||||||
|
.beta-badge-content {
|
||||||
|
@apply mt-2 w-24 rotate-45 bg-beta-background text-center text-xs font-semibold text-beta-foreground
|
||||||
|
}
|
||||||
.export-modal-save-api {
|
.export-modal-save-api {
|
||||||
@apply font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70;
|
@apply font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ export type APIClassType = {
|
||||||
display_name: string;
|
display_name: string;
|
||||||
input_types?: Array<string>;
|
input_types?: Array<string>;
|
||||||
output_types?: Array<string>;
|
output_types?: Array<string>;
|
||||||
|
beta?: boolean;
|
||||||
documentation: string;
|
documentation: string;
|
||||||
[key: string]: Array<string> | string | APITemplateType;
|
[key: string]: Array<string> | string | APITemplateType | boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TemplateVariableType = {
|
export type TemplateVariableType = {
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,8 @@ module.exports = {
|
||||||
"status-yellow": "var(--status-yellow)",
|
"status-yellow": "var(--status-yellow)",
|
||||||
"success-background": "var(--success-background)",
|
"success-background": "var(--success-background)",
|
||||||
"success-foreground": "var(--success-foreground)",
|
"success-foreground": "var(--success-foreground)",
|
||||||
|
"beta-background": "var(--beta-background)",
|
||||||
|
"beta-foreground": "var(--beta-foreground)",
|
||||||
"chat-bot-icon": "var(--chat-bot-icon)",
|
"chat-bot-icon": "var(--chat-bot-icon)",
|
||||||
"chat-user-icon": "var(--chat-user-icon)",
|
"chat-user-icon": "var(--chat-user-icon)",
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue