diff --git a/vision_agent/clients/http.py b/vision_agent/clients/http.py index dc969595..fd6b3e32 100644 --- a/vision_agent/clients/http.py +++ b/vision_agent/clients/http.py @@ -4,7 +4,6 @@ from requests import Session from requests.adapters import HTTPAdapter -from requests.exceptions import ConnectionError, RequestException, Timeout _LOGGER = logging.getLogger(__name__) @@ -38,11 +37,10 @@ def post(self, url: str, payload: Dict[str, Any]) -> Dict[str, Any]: response.raise_for_status() result: Dict[str, Any] = response.json() _LOGGER.info(json.dumps(result)) - except (ConnectionError, Timeout, RequestException) as err: - _LOGGER.warning(f"Error: {err}.") except json.JSONDecodeError: resp_text = response.text _LOGGER.warning(f"Response seems incorrect: '{resp_text}'.") + raise return result def get(self, url: str) -> Dict[str, Any]: @@ -53,9 +51,8 @@ def get(self, url: str) -> Dict[str, Any]: response.raise_for_status() result: Dict[str, Any] = response.json() _LOGGER.info(json.dumps(result)) - except (ConnectionError, Timeout, RequestException) as err: - _LOGGER.warning(f"Error: {err}.") except json.JSONDecodeError: resp_text = response.text _LOGGER.warning(f"Response seems incorrect: '{resp_text}'.") + raise return result diff --git a/vision_agent/clients/landing_public_api.py b/vision_agent/clients/landing_public_api.py index f9d52389..3fd1928e 100644 --- a/vision_agent/clients/landing_public_api.py +++ b/vision_agent/clients/landing_public_api.py @@ -2,8 +2,11 @@ from uuid import UUID from typing import List +from requests.exceptions import HTTPError + from vision_agent.clients.http import BaseHTTP from vision_agent.utils.type_defs import LandingaiAPIKey +from vision_agent.utils.exceptions import FineTuneModelNotFound from vision_agent.tools.tools_types import BboxInputBase64, PromptTask, JobStatus @@ -27,4 +30,9 @@ def launch_fine_tuning_job( def check_fine_tuning_job(self, job_id: UUID) -> JobStatus: url = f"v1/agent/jobs/fine-tuning/{job_id}/status" - return JobStatus(self.get(url)["status"]) + try: + get_job = self.get(url) + except HTTPError as err: + if err.response.status_code == 404: + raise FineTuneModelNotFound() + return JobStatus(get_job["status"]) diff --git a/vision_agent/utils/exceptions.py b/vision_agent/utils/exceptions.py index ce2066b2..22def208 100644 --- a/vision_agent/utils/exceptions.py +++ b/vision_agent/utils/exceptions.py @@ -56,3 +56,9 @@ class FineTuneModelIsNotReady(Exception): If this is raised, it's recommended to wait 5 seconds before trying to use the model again. """ + + +class FineTuneModelNotFound(Exception): + """Exception raised when the fine-tune model is not found. + If this is raised, it's recommended to try another model id. + """