From c8c01402ff919da16f83e90e8f8d22e88d9a2e27 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 26 Sep 2023 15:46:39 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20ra?= =?UTF-8?q?ise=20HTTPException=20when=20build=20method=20contains=20prompt?= =?UTF-8?q?=20type=20argument=20to=20improve=20error=20handling=20and=20pr?= =?UTF-8?q?ovide=20more=20informative=20error=20message=20=F0=9F=90=9B=20f?= =?UTF-8?q?ix(types.py):=20re-raise=20HTTPException=20when=20encountered?= =?UTF-8?q?=20during=20building=20langchain=20template=20custom=20componen?= =?UTF-8?q?t=20to=20propagate=20the=20error=20and=20provide=20more=20infor?= =?UTF-8?q?mative=20error=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/custom_component.py | 12 +++++++++++- src/backend/langflow/interface/types.py | 8 +++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 49ac81ab1..b0c4f8752 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -95,7 +95,17 @@ class CustomComponent(Component, extra=Extra.allow): build_method = build_methods[0] - return build_method["args"] + args = build_method["args"] + for arg in args: + if arg.get("type") == "prompt": + raise HTTPException( + status_code=400, + detail={ + "error": "Type hint Error", + "traceback": "Prompt type is not supported in the build method. Try using PromptTemplate instead.", + }, + ) + return args @property def get_function_entrypoint_return_type(self) -> List[str]: diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index 25d3e8c8b..6708c11c9 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -303,9 +303,9 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) logger.debug("Updated attributes") field_config = build_field_config(custom_component) logger.debug("Built field config") - add_extra_fields( - frontend_node, field_config, custom_component.get_function_entrypoint_args - ) + entrypoint_args = custom_component.get_function_entrypoint_args + + add_extra_fields(frontend_node, field_config, entrypoint_args) logger.debug("Added extra fields") frontend_node = add_code_field( frontend_node, custom_component.code, field_config.get("code", {}) @@ -317,6 +317,8 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) logger.debug("Added base classes") return frontend_node except Exception as exc: + if isinstance(exc, HTTPException): + raise exc raise HTTPException( status_code=400, detail={