From 8887b5ca2885be461e7355f28100d2074eab800e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 3 Nov 2023 10:47:58 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(util.py):=20add=20logic=20to?= =?UTF-8?q?=20extract=20type=20from=20Union[Literal['f-string'],=20Literal?= =?UTF-8?q?['jinja2']]=20to=20improve=20type=20formatting=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(test=5Fprompts=5Ftemplate.py):=20fix=20incorrect=20value?= =?UTF-8?q?=20for=20"validate=5Ftemplate"=20field=20in=20test=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/utils/util.py | 10 ++++++++++ tests/test_prompts_template.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 9dddde032..1c7a7f094 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -276,6 +276,7 @@ def format_dict( _type = remove_optional_wrapper(_type) _type = check_list_type(_type, value) _type = replace_mapping_with_dict(_type) + _type = get_type_from_union_literal(_type) value["type"] = get_formatted_type(key, _type) value["show"] = should_show_field(value, key) @@ -295,6 +296,15 @@ def format_dict( return dictionary +# "Union[Literal['f-string'], Literal['jinja2']]" -> "str" +def get_type_from_union_literal(union_literal: str) -> str: + # if types are literal strings + # the type is a string + if "Literal" in union_literal: + return "str" + return union_literal + + def get_type(value: Any) -> Union[str, type]: """ Retrieves the type value from the dictionary. diff --git a/tests/test_prompts_template.py b/tests/test_prompts_template.py index bc2e935e9..2fc161c6d 100644 --- a/tests/test_prompts_template.py +++ b/tests/test_prompts_template.py @@ -96,7 +96,7 @@ def test_prompt_template(client: TestClient, logged_in_headers): "placeholder": "", "show": False, "multiline": False, - "value": True, + "value": False, "password": False, "name": "validate_template", "type": "bool",