aboutsummaryrefslogtreecommitdiff
path: root/gnqa/paper1_eval/src/errors
diff options
context:
space:
mode:
authorSoloDShelby2024-07-19 14:41:40 +0300
committerSoloDShelby2024-07-19 14:41:40 +0300
commit3fa31b50af2861382fbe2c76406f5a04c3fefc93 (patch)
tree34d581648b0e0d3fc8dbe6577752a4fd433a3258 /gnqa/paper1_eval/src/errors
parent74616897e30c7daafe5e74d34073466464921316 (diff)
downloadgn-ai-3fa31b50af2861382fbe2c76406f5a04c3fefc93.tar.gz
Evaluation code for paper 1
Diffstat (limited to 'gnqa/paper1_eval/src/errors')
-rw-r--r--gnqa/paper1_eval/src/errors/__pycache__/rag_err.cpython-310.pycbin0 -> 1998 bytes
-rw-r--r--gnqa/paper1_eval/src/errors/rag_err.py62
2 files changed, 62 insertions, 0 deletions
diff --git a/gnqa/paper1_eval/src/errors/__pycache__/rag_err.cpython-310.pyc b/gnqa/paper1_eval/src/errors/__pycache__/rag_err.cpython-310.pyc
new file mode 100644
index 0000000..240b761
--- /dev/null
+++ b/gnqa/paper1_eval/src/errors/__pycache__/rag_err.cpython-310.pyc
Binary files differ
diff --git a/gnqa/paper1_eval/src/errors/rag_err.py b/gnqa/paper1_eval/src/errors/rag_err.py
new file mode 100644
index 0000000..e9f7c02
--- /dev/null
+++ b/gnqa/paper1_eval/src/errors/rag_err.py
@@ -0,0 +1,62 @@
+
+# pylint: skip-file
+import json
+
+from requests import HTTPError
+
+
+class UnprocessableEntity(HTTPError):
+ """An HTTP 422 Unprocessable Entity error occurred.
+
+ https://help.helpjuice.com/en_US/api-v3/api-v3#errors
+
+ The request could not be processed, usually due to a missing or invalid parameter.
+
+ The response will also include an error object with an explanation of fields that
+ are missing or invalid. Here is an example:
+
+ .. code-block::
+
+ HTTP/1.1 422 Unprocessable Entity
+
+
+ {
+ "errors": [
+ {
+ "email": "is not valid."
+ }
+ ]
+ }
+ """
+
+ def __init__(self, request, response):
+ """UnprocessableEntity constructor.
+
+ Parses out error information from the error object and passes on to the
+ :obj:`HTTPError` constructor.
+
+ Args:
+ exc (:obj:`HTTPError`): Original exception.
+ """
+ rq_json = next(iter(json.loads(request.body.decode()).values()))
+ errors = response.json()
+
+ for field, error in errors.items():
+ rq_field = rq_json.get(field, None)
+ if not rq_field:
+ continue
+
+ if isinstance(error, list):
+ error = error.insert(0, rq_field)
+ elif isinstance(error, str):
+ error = f"{rq_field} {error}"
+
+ msg = json.dumps(errors)
+ super(HTTPError, self).__init__(
+ msg, request=request, response=response)
+
+
+class LLMError(HTTPError):
+ def __init__(self, request, response, msg):
+ super(HTTPError, self).__init__(
+ msg, request=request, response=response)