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
This commit is contained in:
Gabriel Almeida 2023-05-02 20:12:44 -03:00 • committed by Gabriel Luiz Freitas Almeida
commit 1b10041730
3 changed files with 14 additions and 5 deletions

View file

@ -162,14 +162,23 @@ class FrontendNode(BaseModel):
_type = _type.replace("Optional[", "")[:-1] _type = _type.replace("Optional[", "")[:-1]
# Check for list type # Check for list type
if "List" in _type: if "List" in _type or "Sequence" in _type:
_type = _type.replace("List[", "")[:-1] _type = _type.replace("List[", "")
_type = _type.replace("Sequence[", "")[:-1]
field.is_list = True field.is_list = True
# Replace 'Mapping' with 'dict' # Replace 'Mapping' with 'dict'
if "Mapping" in _type: if "Mapping" in _type:
_type = _type.replace("Mapping", "dict") _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 # Change type from str to Tool
field.field_type = "Tool" if key in {"allowed_tools"} else field.field_type field.field_type = "Tool" if key in {"allowed_tools"} else field.field_type

View file

@ -48,6 +48,7 @@ def test_zero_shot_agent(client: TestClient):
"type": "Tool", "type": "Tool",
"list": True, "list": True,
"advanced": False, "advanced": False,
"value": [],
} }

View file

@ -291,7 +291,7 @@ def test_openai(client: TestClient):
"multiline": False, "multiline": False,
"password": False, "password": False,
"name": "request_timeout", "name": "request_timeout",
"type": "Union[float, Tuple[float, float], NoneType]", "type": "float",
"list": False, "list": False,
"advanced": False, "advanced": False,
} }
@ -418,10 +418,9 @@ def test_chat_open_ai(client: TestClient):
"placeholder": "", "placeholder": "",
"show": False, "show": False,
"multiline": False, "multiline": False,
"value": 60,
"password": False, "password": False,
"name": "request_timeout", "name": "request_timeout",
"type": "int", "type": "float",
"list": False, "list": False,
"advanced": False, "advanced": False,
} }