makes Text an input_type if field_type is str
This commit is contained in:
parent
4bba0212ff
commit
42fb9aa4aa
1 changed files with 18 additions and 2 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
from typing import Any, Callable, Optional, Union
|
from typing import Any, Callable, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field, field_serializer
|
|
||||||
|
|
||||||
from langflow.field_typing.range_spec import RangeSpec
|
from langflow.field_typing.range_spec import RangeSpec
|
||||||
|
from pydantic import BaseModel, ConfigDict, Field, field_serializer, model_serializer
|
||||||
|
|
||||||
|
|
||||||
class TemplateField(BaseModel):
|
class TemplateField(BaseModel):
|
||||||
|
|
@ -67,6 +66,17 @@ class TemplateField(BaseModel):
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return self.model_dump(by_alias=True, exclude_none=True)
|
return self.model_dump(by_alias=True, exclude_none=True)
|
||||||
|
|
||||||
|
@model_serializer(mode="wrap")
|
||||||
|
def serialize_model(self, handler):
|
||||||
|
result = handler(self)
|
||||||
|
# If the field is str, we add the Text input type
|
||||||
|
if self.field_type == "str":
|
||||||
|
if "input_types" not in result:
|
||||||
|
result["input_types"] = ["Text"]
|
||||||
|
else:
|
||||||
|
result["input_types"].append("Text")
|
||||||
|
return result
|
||||||
|
|
||||||
@field_serializer("file_path")
|
@field_serializer("file_path")
|
||||||
def serialize_file_path(self, value):
|
def serialize_file_path(self, value):
|
||||||
return value if self.field_type == "file" else ""
|
return value if self.field_type == "file" else ""
|
||||||
|
|
@ -76,3 +86,9 @@ class TemplateField(BaseModel):
|
||||||
if value == "float" and self.range_spec is None:
|
if value == "float" and self.range_spec is None:
|
||||||
self.range_spec = RangeSpec()
|
self.range_spec = RangeSpec()
|
||||||
return value
|
return value
|
||||||
|
return value
|
||||||
|
return value
|
||||||
|
return value
|
||||||
|
return value
|
||||||
|
return value
|
||||||
|
return value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue