From 591237c5dd313631c453bf000af1b357081f137c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 6 Nov 2023 21:01:55 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(util.py):=20add=20get=5Fty?= =?UTF-8?q?pe=5Ffrom=5Funion=5Fliteral=20function=20to=20handle=20union=20?= =?UTF-8?q?literals=20in=20format=5Fdict=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔧 chore(util.py): add get_type_from_union_literal function to handle union literals in format_dict function --- src/backend/langflow/utils/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index c23c559e4..e17687d88 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) @@ -462,3 +463,11 @@ def build_loader_repr_from_documents(documents: List[Document]) -> str: \nAvg. Document Length (characters): {int(avg_length)} Documents: {documents[:3]}...""" return "0 documents" + + +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