Merge branch 'two_edges' of https://github.com/langflow-ai/langflow into two_edges
This commit is contained in:
commit
63eee10f2e
11 changed files with 2901 additions and 3893 deletions
|
|
@ -4,7 +4,6 @@ from uuid import UUID
|
|||
|
||||
import yaml
|
||||
from git import TYPE_CHECKING
|
||||
from loguru import logger
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langflow.inputs.inputs import InputTypes
|
||||
|
|
@ -52,18 +51,20 @@ class Component(CustomComponent):
|
|||
self.map_inputs(self.inputs)
|
||||
|
||||
def map_inputs(self, inputs: List[Input]):
|
||||
self._inputs = {}
|
||||
self.inputs = inputs
|
||||
for input_ in inputs:
|
||||
self._inputs[input_.name] = input_
|
||||
|
||||
def _validate_inputs(self, params: dict):
|
||||
# Params keys are the `name` attribute of the Input objects
|
||||
for key, value in params.items():
|
||||
for key, value in params.copy().items():
|
||||
if key not in self._inputs:
|
||||
continue
|
||||
input_ = self._inputs[key]
|
||||
# BaseInputMixin has a `validate_assignment=True`
|
||||
input_.value = value
|
||||
params[input_.name] = input_.value
|
||||
|
||||
def set_attributes(self, params: dict):
|
||||
self._validate_inputs(params)
|
||||
|
|
@ -71,10 +72,6 @@ class Component(CustomComponent):
|
|||
if key in self.__dict__:
|
||||
raise ValueError(f"Key {key} already exists in {self.__class__.__name__}")
|
||||
setattr(self, key, value)
|
||||
for input_ in self.inputs:
|
||||
if input_.name not in params:
|
||||
setattr(self, input_.name, input_.value)
|
||||
logger.warning(f"Input {input_.name} not found in arguments")
|
||||
self._arguments = params
|
||||
|
||||
def _set_outputs(self, outputs: List[dict]):
|
||||
|
|
|
|||
|
|
@ -43,29 +43,29 @@ class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin): # noqa:
|
|||
class TextInput(StrInput):
|
||||
input_types: list[str] = ["Data", "Message", "Text"]
|
||||
|
||||
# @field_validator("value")
|
||||
# @classmethod
|
||||
# def validate_value(cls, v: Any, _info):
|
||||
# value = None
|
||||
# if isinstance(v, str):
|
||||
# value = v
|
||||
# elif isinstance(v, Message):
|
||||
# value = v.text
|
||||
# elif isinstance(v, Data):
|
||||
# if v.text_key in v.data:
|
||||
# value = v.data[v.text_key]
|
||||
# else:
|
||||
# keys = ", ".join(v.data.keys())
|
||||
# input_name = _info.data["name"]
|
||||
# raise ValueError(
|
||||
# f"The input to '{input_name}' must contain the key '{v.text_key}'."
|
||||
# f"You can set `text_key` to one of the following keys: {keys} or set the value using another Component."
|
||||
# )
|
||||
# else:
|
||||
# raise ValueError(f"Invalid input type {type(v)}")
|
||||
# if isinstance(value, str):
|
||||
# return value
|
||||
# raise ValueError(f"Invalid value type {type(value)}")
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
def validate_value(cls, v: Any, _info):
|
||||
value = None
|
||||
if isinstance(v, str):
|
||||
value = v
|
||||
elif isinstance(v, Message):
|
||||
value = v.text
|
||||
elif isinstance(v, Data):
|
||||
if v.text_key in v.data:
|
||||
value = v.data[v.text_key]
|
||||
else:
|
||||
keys = ", ".join(v.data.keys())
|
||||
input_name = _info.data["name"]
|
||||
raise ValueError(
|
||||
f"The input to '{input_name}' must contain the key '{v.text_key}'."
|
||||
f"You can set `text_key` to one of the following keys: {keys} or set the value using another Component."
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Invalid input type {type(v)}")
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
raise ValueError(f"Invalid value type {type(value)}")
|
||||
|
||||
|
||||
class MultilineInput(BaseInputMixin):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue