From b2e784dcb741d4ccdf001519546f80d5361937fb Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 27 Jul 2023 17:19:24 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20fix=20issue=20w?= =?UTF-8?q?ith=20incorrect=20assignment=20of=20field=5Fadvanced=20variable?= =?UTF-8?q?=20in=20add=5Fnew=5Fcustom=5Ffield=20function=20=E2=9C=A8=20fea?= =?UTF-8?q?t(types.py):=20add=20support=20for=20advanced=20field=20configu?= =?UTF-8?q?ration=20in=20add=5Fnew=5Fcustom=5Ffield=20function=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20fix=20issue=20with=20incorrect?= =?UTF-8?q?=20assignment=20of=20field=5Fadvanced=20variable=20in=20add=5Fc?= =?UTF-8?q?ode=5Ffield=20function=20=E2=9C=A8=20feat(types.py):=20add=20su?= =?UTF-8?q?pport=20for=20advanced=20field=20configuration=20in=20add=5Fcod?= =?UTF-8?q?e=5Ffield=20function=20=F0=9F=90=9B=20fix(types.py):=20fix=20is?= =?UTF-8?q?sue=20with=20incorrect=20sorting=20of=20function=5Fargs=20in=20?= =?UTF-8?q?add=5Fextra=5Ffields=20function=20=E2=9C=A8=20feat(types.py):?= =?UTF-8?q?=20add=20sorting=20of=20function=5Fargs=20in=20add=5Fextra=5Ffi?= =?UTF-8?q?elds=20function=20=F0=9F=90=9B=20fix(types.py):=20fix=20issue?= =?UTF-8?q?=20with=20incorrect=20usage=20of=20field=5Fconfig=20in=20add=5F?= =?UTF-8?q?code=5Ffield=20function=20=E2=9C=A8=20feat(types.py):=20add=20s?= =?UTF-8?q?upport=20for=20field=5Fconfig=20in=20add=5Fcode=5Ffield=20funct?= =?UTF-8?q?ion=20=F0=9F=90=9B=20fix(types.py):=20fix=20issue=20with=20inco?= =?UTF-8?q?rrect=20usage=20of=20field=5Fconfig=20in=20build=5Flangchain=5F?= =?UTF-8?q?template=5Fcustom=5Fcomponent=20function=20=E2=9C=A8=20feat(typ?= =?UTF-8?q?es.py):=20add=20support=20for=20field=5Fconfig=20in=20build=5Fl?= =?UTF-8?q?angchain=5Ftemplate=5Fcustom=5Fcomponent=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/types.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index e68a07b44..c6a901baa 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -99,6 +99,7 @@ def add_new_custom_field( field_type = field_config.pop("field_type", field_type) field_type = process_type(field_type) field_value = field_config.pop("value", field_value) + field_advanced = field_config.pop("advanced", False) if "name" in field_config: warnings.warn( @@ -115,7 +116,7 @@ def add_new_custom_field( value=field_value, show=True, required=required, - advanced=False, + advanced=field_advanced, placeholder=placeholder, display_name=display_name, **field_config, @@ -127,8 +128,9 @@ def add_new_custom_field( # TODO: Move to correct place -def add_code_field(template, raw_code): +def add_code_field(template, raw_code, field_config): # Field with the Python code to allow update + code_field = { "code": { "dynamic": True, @@ -139,7 +141,7 @@ def add_code_field(template, raw_code): "value": raw_code, "password": False, "name": "code", - "advanced": False, + "advanced": field_config.pop("advanced", False), "type": "code", "list": False, } @@ -199,6 +201,8 @@ def add_extra_fields(frontend_node, field_config, function_args): """Add extra fields to the frontend node""" if function_args is None: return + # sort function_args which is a list of dicts + function_args.sort(key=lambda x: x["name"]) for extra_field in function_args: if "name" not in extra_field or extra_field["name"] == "self": @@ -269,7 +273,9 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) frontend_node, field_config, custom_component.get_function_entrypoint_args ) - frontend_node = add_code_field(frontend_node, custom_component.code) + frontend_node = add_code_field( + frontend_node, custom_component.code, field_config.get("code", {}) + ) add_base_classes( frontend_node, custom_component.get_function_entrypoint_return_type