Fixes type hint "prompt" (#969)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-26 17:20:03 -03:00 committed by GitHub
commit a6ba2a24d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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={