🚀 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,9 +53,8 @@ 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
|
||||||
|
if not isinstance(signature, FrontendNode):
|
||||||
fields = [
|
fields = [
|
||||||
TemplateField(
|
TemplateField(
|
||||||
name=key,
|
name=key,
|
||||||
|
|
@ -74,9 +73,13 @@ class LangChainTypeCreator(BaseModel, ABC):
|
||||||
if key != "_type"
|
if key != "_type"
|
||||||
]
|
]
|
||||||
template = Template(type_name=name, fields=fields)
|
template = Template(type_name=name, fields=fields)
|
||||||
return self.frontend_node_class(
|
signature = self.frontend_node_class(
|
||||||
template=template,
|
template=template,
|
||||||
description=signature.get("description", ""),
|
description=signature.get("description", ""),
|
||||||
base_classes=signature["base_classes"],
|
base_classes=signature["base_classes"],
|
||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
signature.add_extra_fields()
|
||||||
|
|
||||||
|
return signature
|
||||||
|
|
|
||||||
|
|
@ -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