Refactor custom.py for better error handling

- Modifies the `CustomComponent` class to handle errors using `HTTPException` from FastAPI
- Removes the unused `HTTPExceptionWithTraceback` class
- Updates the error response format with `err.msg` and `traceback.format_exc()`
This commit is contained in:
gustavoschaedler 2023-07-05 16:23:32 +01:00
commit ae5bc1e203

View file

@ -12,12 +12,6 @@ from langchain.agents.tools import Tool
from fastapi import HTTPException
class HTTPExceptionWithTraceback(HTTPException):
def __init__(self, status_code, detail=None, traceback=None):
super().__init__(status_code, detail)
self.traceback = traceback
class Function(BaseModel):
code: str
function: Optional[Callable] = None
@ -170,13 +164,8 @@ class CustomComponent(BaseModel):
detail={
'error': err.msg,
'traceback': traceback.format_exc()
}
)
# raise HTTPExceptionWithTraceback(
# status_code=400,
# detail=err.msg,
# traceback=traceback.format_exc()
# ) from err
},
) from err
for node in module.body:
if isinstance(node, (ast.Import, ast.ImportFrom)):