🚀 feat(langflow): add support for extra fields in VectorStoreFrontendNode (#396)

 feat(template): add method to add fields to a template
The VectorStoreFrontendNode now supports adding extra fields to its
template. The add_extra_fields method is called after the node is loaded
and adds the weaviate_url field to the template if the node is of type
Weaviate. The Template class now has a method to add fields to a
template. This method is used by the VectorStoreFrontendNode to add the
weaviate_url field to its template.
This commit is contained in:
Alexandre Henrique Pereira Tavares 2023-05-29 16:15:25 -03:00 committed by GitHub
commit 8039a58af0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 25 deletions

View file

@ -53,30 +53,33 @@ class LangChainTypeCreator(BaseModel, ABC):
signature = self.get_signature(name)
if signature is None:
logger.error(f"Node {name} not loaded")
return None
if isinstance(signature, FrontendNode):
return signature
fields = [
TemplateField(
name=key,
field_type=value["type"],
required=value.get("required", False),
placeholder=value.get("placeholder", ""),
is_list=value.get("list", False),
show=value.get("show", True),
multiline=value.get("multiline", False),
value=value.get("value", None),
suffixes=value.get("suffixes", []),
file_types=value.get("fileTypes", []),
content=value.get("content", None),
if not isinstance(signature, FrontendNode):
fields = [
TemplateField(
name=key,
field_type=value["type"],
required=value.get("required", False),
placeholder=value.get("placeholder", ""),
is_list=value.get("list", False),
show=value.get("show", True),
multiline=value.get("multiline", False),
value=value.get("value", None),
suffixes=value.get("suffixes", []),
file_types=value.get("fileTypes", []),
content=value.get("content", None),
)
for key, value in signature["template"].items()
if key != "_type"
]
template = Template(type_name=name, fields=fields)
signature = self.frontend_node_class(
template=template,
description=signature.get("description", ""),
base_classes=signature["base_classes"],
name=name,
)
for key, value in signature["template"].items()
if key != "_type"
]
template = Template(type_name=name, fields=fields)
return self.frontend_node_class(
template=template,
description=signature.get("description", ""),
base_classes=signature["base_classes"],
name=name,
)
signature.add_extra_fields()
return signature

View file

@ -24,6 +24,9 @@ class FrontendNode(BaseModel):
}
}
def add_extra_fields(self) -> None:
pass
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
"""Formats a given field based on its attributes and value."""

View file

@ -5,6 +5,21 @@ from langflow.template.frontend_node.base import FrontendNode
class VectorStoreFrontendNode(FrontendNode):
def add_extra_fields(self) -> None:
if self.template.type_name == "Weaviate":
extra_field = TemplateField(
name="weaviate_url",
field_type="str",
required=True,
placeholder="http://localhost:8080",
show=True,
advanced=False,
multiline=False,
value="http://localhost:8080",
)
self.template.add_field(extra_field)
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
FrontendNode.format_field(field, name)

View file

@ -23,3 +23,6 @@ class Template(BaseModel):
result = {field.name: field.to_dict() for field in self.fields}
result["_type"] = self.type_name # type: ignore
return result
def add_field(self, field: TemplateField) -> None:
self.fields.append(field)