about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gn3/llms/client.py27
-rw-r--r--gn3/llms/errors.py9
2 files changed, 26 insertions, 10 deletions
diff --git a/gn3/llms/client.py b/gn3/llms/client.py
index 5db19e4..042becd 100644
--- a/gn3/llms/client.py
+++ b/gn3/llms/client.py
@@ -14,6 +14,8 @@ from requests import Session
 from requests.adapters import HTTPAdapter
 from urllib.request import urlretrieve
 from urllib.parse import quote
+from gn3.llms.errors import UnprocessableEntity
+from gn3.llms.errors import LLMError
 
 basedir = os.path.join(os.path.dirname(__file__))
 
@@ -116,7 +118,8 @@ class GeneNetworkQAClient(Session):
 
     @staticmethod
     def negative_status_msg(response):
-        return f"Problems\n\tStatus code => {response.status_code}\n\tReason => {response.reason}"
+        return f"Error: Status code -{response.status_code}- Reason::{response.reason}"
+      #  return f"Problems\n\tStatus code => {response.status_code}\n\tReason => {response.reason}"
 
     def ask(self, exUrl, *args, **kwargs):
         askUrl = self.BASE_URL + exUrl
@@ -142,12 +145,20 @@ class GeneNetworkQAClient(Session):
             try:
                 response = super().request(method, url, *args, **kwargs)
                 response.raise_for_status()
-            except requests.exceptions.RequestException as exc:
-                if exc.response.status_code == 422:
-                    raise UnprocessableEntity(exc.request, exc.response)
-                    # from exc
-                elif i == max_retries - 1:
-                    raise exc
+
+            except requests.exceptions.HTTPError as error:
+                if error.response.status_code ==500:
+                    raise LLMError(error.request, error.response, f"Response Error,status_code:{error.response.status_code},Reason: Use of Invalid Token")
+                elif error.response.status_code ==404:
+                    raise LLMError(error.request,error.response,f"404 Client Error: Not Found for url: {self.BASE_URL}")
+                raise error
+
+            except requests.exceptions.RequestException as error:
+                raise error 
+
+
+
+
             if response.ok:
                 if method.lower() == "get" and response.json().get("data") is None:
                     time.sleep(retry_delay)
@@ -206,4 +217,4 @@ class GeneNetworkQAClient(Session):
             context = resp_text.get('data', {}).get('context', '')
             return answer, context
         else:
-            return res, "Unfortunately, I have nothing."
\ No newline at end of file
+            return res, "Unfortunately, I have nothing."
diff --git a/gn3/llms/errors.py b/gn3/llms/errors.py
index 006e034..e9f7c02 100644
--- a/gn3/llms/errors.py
+++ b/gn3/llms/errors.py
@@ -4,6 +4,7 @@ import json
 
 from requests import HTTPError
 
+
 class UnprocessableEntity(HTTPError):
     """An HTTP 422 Unprocessable Entity error occurred.
 
@@ -51,7 +52,11 @@ class UnprocessableEntity(HTTPError):
                 error = f"{rq_field} {error}"
 
         msg = json.dumps(errors)
-        super(HTTPError, self).__init__(msg, request=request, response=response)
+        super(HTTPError, self).__init__(
+            msg, request=request, response=response)
 
 
-        
\ No newline at end of file
+class LLMError(HTTPError):
+    def __init__(self, request, response, msg):
+        super(HTTPError, self).__init__(
+            msg, request=request, response=response)