🐛 fix(custom_component.py): update error message to include the specific type hint that is used but not imported in the code
🐛 fix(directory_reader.py): update error message to include the specific type hint that is used but not imported in the code
This commit is contained in:
parent
082a61eadd
commit
267d543420
2 changed files with 10 additions and 8 deletions
|
|
@ -30,6 +30,8 @@ class CustomComponent(Component, extra=Extra.allow):
|
|||
return self.field_config
|
||||
|
||||
def _class_template_validation(self, code: str) -> bool:
|
||||
TYPE_HINT_LIST = ["Optional", "Prompt", "PromptTemplate", "LLMChain"]
|
||||
|
||||
if not code:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
|
@ -40,14 +42,14 @@ class CustomComponent(Component, extra=Extra.allow):
|
|||
)
|
||||
|
||||
reader = DirectoryReader("", False)
|
||||
if reader.is_type_hint_used_but_not_imported("Optional", code):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
|
||||
for type_hint in TYPE_HINT_LIST:
|
||||
if reader.is_type_hint_used_but_not_imported(type_hint, code):
|
||||
error_detail = {
|
||||
"error": "Type hint Error",
|
||||
"traceback": "Name type hint 'Optional' is not defined",
|
||||
},
|
||||
)
|
||||
"traceback": f"Type hint '{type_hint}' is used but not imported in the code.",
|
||||
}
|
||||
raise HTTPException(status_code=400, detail=error_detail)
|
||||
|
||||
def is_check_valid(self) -> bool:
|
||||
return self._class_template_validation(self.code)
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class DirectoryReader:
|
|||
elif not self.validate_build(file_content):
|
||||
return False, "Missing build function"
|
||||
elif self.is_type_hint_used_but_not_imported("Optional", file_content):
|
||||
return False, "Name type hint 'Optional' is not defined"
|
||||
return False, "Type hint 'Optional' is used but not imported in the code."
|
||||
else:
|
||||
if self.compress_code_field:
|
||||
file_content = str(StringCompressor(file_content).compress_string())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue