From 3ae51da36e5ea31590ee8b6b2ddab282058b69a2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 18 Sep 2023 18:43:07 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(UpdateRequest.py):=20chang?= =?UTF-8?q?e=20field=5Ftype=20from=20"code"=20to=20"NestedDict"=20to=20imp?= =?UTF-8?q?rove=20clarity=20and=20semantics=20=F0=9F=94=A7=20chore(base.py?= =?UTF-8?q?):=20handle=20"dict"=20and=20"NestedDict"=20types=20in=20params?= =?UTF-8?q?=20parsing=20to=20ensure=20correct=20conversion=20from=20fronte?= =?UTF-8?q?nd=20data=20=F0=9F=94=A7=20chore(llms.py):=20change=20field=5Ft?= =?UTF-8?q?ype=20from=20"code"=20to=20"dict"=20for=20model=5Fkwargs=20fiel?= =?UTF-8?q?d=20to=20improve=20semantics=20=F0=9F=94=A7=20chore(utilities.p?= =?UTF-8?q?y):=20remove=20field=5Ftype=20"code"=20for=20fields=20with=20di?= =?UTF-8?q?ct=20values=20to=20improve=20consistency=20=F0=9F=94=A7=20chore?= =?UTF-8?q?(constants.py):=20add=20"dict"=20and=20"NestedDict"=20to=20DIRE?= =?UTF-8?q?CT=5FTYPES=20list=20to=20reflect=20available=20field=20types=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(util.py):=20remove=20replace=5Fdict=5Ftype?= =?UTF-8?q?=5Fwith=5Fcode=20function=20as=20it=20is=20no=20longer=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/components/utilities/UpdateRequest.py | 2 +- src/backend/langflow/graph/vertex/base.py | 12 ++++++++++++ src/backend/langflow/template/frontend_node/llms.py | 2 +- .../langflow/template/frontend_node/utilities.py | 1 - src/backend/langflow/utils/constants.py | 12 +++++++++++- src/backend/langflow/utils/util.py | 2 -- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/components/utilities/UpdateRequest.py b/src/backend/langflow/components/utilities/UpdateRequest.py index 6e8991794..d18c94a56 100644 --- a/src/backend/langflow/components/utilities/UpdateRequest.py +++ b/src/backend/langflow/components/utilities/UpdateRequest.py @@ -15,7 +15,7 @@ class UpdateRequest(CustomComponent): "url": {"display_name": "URL", "info": "The URL to make the request to."}, "headers": { "display_name": "Headers", - "field_type": "code", + "field_type": "NestedDict", "info": "The headers to send with the request.", }, "code": {"show": False}, diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 0f9a5e8a9..715babf25 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -122,6 +122,18 @@ class Vertex: except Exception as exc: logger.debug(f"Error parsing code: {exc}") params[key] = value.get("value") + elif value.get("type") in ["dict", "NestedDict"]: + # When dict comes from the frontend it comes as a + # list of dicts, so we need to convert it to a dict + # before passing it to the build method + _value = value.get("value") + if isinstance(_value, list): + params[key] = { + item["key"]: item["value"] + for item in value.get("value", []) + } + elif isinstance(_value, dict): + params[key] = _value else: params[key] = value.get("value") diff --git a/src/backend/langflow/template/frontend_node/llms.py b/src/backend/langflow/template/frontend_node/llms.py index 01098724e..b8e007a27 100644 --- a/src/backend/langflow/template/frontend_node/llms.py +++ b/src/backend/langflow/template/frontend_node/llms.py @@ -131,7 +131,7 @@ class LLMFrontendNode(FrontendNode): if display_name := display_names_dict.get(field.name): field.display_name = display_name if field.name == "model_kwargs": - field.field_type = "code" + field.field_type = "dict" field.advanced = True field.show = True elif field.name in [ diff --git a/src/backend/langflow/template/frontend_node/utilities.py b/src/backend/langflow/template/frontend_node/utilities.py index 9dedacd0f..a5adb219d 100644 --- a/src/backend/langflow/template/frontend_node/utilities.py +++ b/src/backend/langflow/template/frontend_node/utilities.py @@ -21,5 +21,4 @@ class UtilitiesFrontendNode(FrontendNode): field.field_type = "str" if isinstance(field.value, dict): - field.field_type = "code" field.value = orjson_dumps(field.value) diff --git a/src/backend/langflow/utils/constants.py b/src/backend/langflow/utils/constants.py index e473d855b..43f92f651 100644 --- a/src/backend/langflow/utils/constants.py +++ b/src/backend/langflow/utils/constants.py @@ -48,4 +48,14 @@ def python_function(text: str) -> str: return text """ -DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"] +DIRECT_TYPES = [ + "str", + "bool", + "dict", + "int", + "float", + "Any", + "prompt", + "code", + "NestedDict", +] diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 921f913c6..519ee79ca 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -276,8 +276,6 @@ def format_dict( value["password"] = is_password_field(key) value["multiline"] = is_multiline_field(key) - replace_dict_type_with_code(value) - if key == "dict_": set_dict_file_attributes(value)