🚀 feat(langflow): add support for extra fields in VectorStoreFrontendNode
✨ 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:
parent
20a438428f
commit
3614296fd8
4 changed files with 49 additions and 25 deletions
|
|
@ -53,30 +53,33 @@ class LangChainTypeCreator(BaseModel, ABC):
|
||||||
signature = self.get_signature(name)
|
signature = self.get_signature(name)
|
||||||
if signature is None:
|
if signature is None:
|
||||||
logger.error(f"Node {name} not loaded")
|
logger.error(f"Node {name} not loaded")
|
||||||
return None
|
|
||||||
if isinstance(signature, FrontendNode):
|
|
||||||
return signature
|
return signature
|
||||||
fields = [
|
if not isinstance(signature, FrontendNode):
|
||||||
TemplateField(
|
fields = [
|
||||||
name=key,
|
TemplateField(
|
||||||
field_type=value["type"],
|
name=key,
|
||||||
required=value.get("required", False),
|
field_type=value["type"],
|
||||||
placeholder=value.get("placeholder", ""),
|
required=value.get("required", False),
|
||||||
is_list=value.get("list", False),
|
placeholder=value.get("placeholder", ""),
|
||||||
show=value.get("show", True),
|
is_list=value.get("list", False),
|
||||||
multiline=value.get("multiline", False),
|
show=value.get("show", True),
|
||||||
value=value.get("value", None),
|
multiline=value.get("multiline", False),
|
||||||
suffixes=value.get("suffixes", []),
|
value=value.get("value", None),
|
||||||
file_types=value.get("fileTypes", []),
|
suffixes=value.get("suffixes", []),
|
||||||
content=value.get("content", None),
|
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"
|
signature.add_extra_fields()
|
||||||
]
|
|
||||||
template = Template(type_name=name, fields=fields)
|
return signature
|
||||||
return self.frontend_node_class(
|
|
||||||
template=template,
|
|
||||||
description=signature.get("description", ""),
|
|
||||||
base_classes=signature["base_classes"],
|
|
||||||
name=name,
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ class FrontendNode(BaseModel):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def add_extra_fields(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
||||||
"""Formats a given field based on its attributes and value."""
|
"""Formats a given field based on its attributes and value."""
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,21 @@ from langflow.template.frontend_node.base import FrontendNode
|
||||||
|
|
||||||
|
|
||||||
class VectorStoreFrontendNode(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
|
@staticmethod
|
||||||
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
||||||
FrontendNode.format_field(field, name)
|
FrontendNode.format_field(field, name)
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,6 @@ class Template(BaseModel):
|
||||||
result = {field.name: field.to_dict() for field in self.fields}
|
result = {field.name: field.to_dict() for field in self.fields}
|
||||||
result["_type"] = self.type_name # type: ignore
|
result["_type"] = self.type_name # type: ignore
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def add_field(self, field: TemplateField) -> None:
|
||||||
|
self.fields.append(field)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue