From 1b10041730fd551761bb74dbc414c7e39fbaf0a4 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Tue, 2 May 2023 20:12:44 -0300 Subject: [PATCH] refactor(base.py): simplify type of Union fields to the first type in the Union fix(test_agents_template.py): set value of list field to an empty list fix(test_llms_template.py): change type of 'request_timeout' field to float --- src/backend/langflow/template/base.py | 13 +++++++++++-- tests/test_agents_template.py | 1 + tests/test_llms_template.py | 5 ++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/template/base.py b/src/backend/langflow/template/base.py index fd34a19f2..5273782ed 100644 --- a/src/backend/langflow/template/base.py +++ b/src/backend/langflow/template/base.py @@ -162,14 +162,23 @@ class FrontendNode(BaseModel): _type = _type.replace("Optional[", "")[:-1] # Check for list type - if "List" in _type: - _type = _type.replace("List[", "")[:-1] + if "List" in _type or "Sequence" in _type: + _type = _type.replace("List[", "") + _type = _type.replace("Sequence[", "")[:-1] field.is_list = True # Replace 'Mapping' with 'dict' if "Mapping" in _type: _type = _type.replace("Mapping", "dict") + # {'type': 'Union[float, Tuple[float, float], NoneType]'} != {'type': 'float'} + if "Union" in _type: + _type = _type.replace("Union[", "")[:-1] + _type = _type.split(",")[0] + _type = _type.replace("]", "").replace("[", "") + + field.field_type = _type + # Change type from str to Tool field.field_type = "Tool" if key in {"allowed_tools"} else field.field_type diff --git a/tests/test_agents_template.py b/tests/test_agents_template.py index 750050c25..db746a424 100644 --- a/tests/test_agents_template.py +++ b/tests/test_agents_template.py @@ -48,6 +48,7 @@ def test_zero_shot_agent(client: TestClient): "type": "Tool", "list": True, "advanced": False, + "value": [], } diff --git a/tests/test_llms_template.py b/tests/test_llms_template.py index 9f5fdfb4d..dc0149520 100644 --- a/tests/test_llms_template.py +++ b/tests/test_llms_template.py @@ -291,7 +291,7 @@ def test_openai(client: TestClient): "multiline": False, "password": False, "name": "request_timeout", - "type": "Union[float, Tuple[float, float], NoneType]", + "type": "float", "list": False, "advanced": False, } @@ -418,10 +418,9 @@ def test_chat_open_ai(client: TestClient): "placeholder": "", "show": False, "multiline": False, - "value": 60, "password": False, "name": "request_timeout", - "type": "int", + "type": "float", "list": False, "advanced": False, }