From 12100489a73094016602926183e0ee51002fb9c6 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Wed, 22 May 2024 13:37:32 +0300 Subject: Register LLM error in app. * do refactoring for gn3:llm:errors --- gn3/errors.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'gn3/errors.py') diff --git a/gn3/errors.py b/gn3/errors.py index 1833bf6..ac9e070 100644 --- a/gn3/errors.py +++ b/gn3/errors.py @@ -16,7 +16,7 @@ from authlib.oauth2.rfc6749.errors import OAuth2Error from flask import Flask, jsonify, Response, current_app from gn3.auth.authorisation.errors import AuthorisationError - +from gn3.llms.errors import LLMError def add_trace(exc: Exception, jsonmsg: dict) -> dict: """Add the traceback to the error handling object.""" @@ -106,6 +106,20 @@ def handle_generic(exc: Exception) -> Response: return resp +def handle_llm_error(exc: Exception) -> Response: + """ Handle llm erros if not handled anywhere else. """ + resp = jsonify({ + "query": exc.query if exc.query else "", + "error_type": type(exc).__name__, + "error": ( + exc.args if bool(exc.args) else "Fahamu gnqa error occurred" + ), + "trace": traceback.format_exc() + }) + resp.status_code = 500 + return resp + + def register_error_handlers(app: Flask): """Register application-level error handlers.""" app.register_error_handler(NotFound, page_not_found) @@ -115,6 +129,7 @@ def register_error_handlers(app: Flask): app.register_error_handler(AuthorisationError, handle_authorisation_error) app.register_error_handler(RemoteDisconnected, internal_server_error) app.register_error_handler(URLError, url_server_error) + app.register_error_handler(LLMError, handle_llm_error) for exc in ( EndPointInternalError, EndPointNotFound, -- cgit v1.2.3 From 67c71507c84d474ac13681f16d994e7967321ddb Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Fri, 24 May 2024 16:21:50 +0300 Subject: Return first argument as error message. --- gn3/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gn3/errors.py') diff --git a/gn3/errors.py b/gn3/errors.py index ac9e070..ad08ae5 100644 --- a/gn3/errors.py +++ b/gn3/errors.py @@ -112,7 +112,7 @@ def handle_llm_error(exc: Exception) -> Response: "query": exc.query if exc.query else "", "error_type": type(exc).__name__, "error": ( - exc.args if bool(exc.args) else "Fahamu gnqa error occurred" + exc.args[0] if bool(exc.args) else "Fahamu gnqa error occurred" ), "trace": traceback.format_exc() }) -- cgit v1.2.3 From 8512d9a606fbfff864345d82c210e281a6d943bf Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Fri, 24 May 2024 16:27:51 +0300 Subject: Initiliaze second args to LLMError as query parameter. --- gn3/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gn3/errors.py') diff --git a/gn3/errors.py b/gn3/errors.py index ad08ae5..8331028 100644 --- a/gn3/errors.py +++ b/gn3/errors.py @@ -109,7 +109,7 @@ def handle_generic(exc: Exception) -> Response: def handle_llm_error(exc: Exception) -> Response: """ Handle llm erros if not handled anywhere else. """ resp = jsonify({ - "query": exc.query if exc.query else "", + "query": exc.args[1], "error_type": type(exc).__name__, "error": ( exc.args[0] if bool(exc.args) else "Fahamu gnqa error occurred" -- cgit v1.2.3 From 7b17ab9d98f6a12f2a5b9b0eec8ff4c2c3ef2a5e Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Thu, 29 Aug 2024 10:28:34 +0300 Subject: Add logging for gn llm errors. --- gn3/errors.py | 1 + 1 file changed, 1 insertion(+) (limited to 'gn3/errors.py') diff --git a/gn3/errors.py b/gn3/errors.py index 8331028..c53604f 100644 --- a/gn3/errors.py +++ b/gn3/errors.py @@ -108,6 +108,7 @@ def handle_generic(exc: Exception) -> Response: def handle_llm_error(exc: Exception) -> Response: """ Handle llm erros if not handled anywhere else. """ + current_app.logger.error(exc) resp = jsonify({ "query": exc.args[1], "error_type": type(exc).__name__, -- cgit v1.2.3