🐛 fix(custom_component.py): raise HTTPException when build method contains prompt type argument to improve error handling and provide more informative error message

🐛 fix(types.py): re-raise HTTPException when encountered during building langchain template custom component to propagate the error and provide more informative error message
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-26 15:46:39 -03:00
commit c8c01402ff
2 changed files with 16 additions and 4 deletions

View file

@ -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]:

View file

@ -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={