From 89dc9b7b8f1db6b598975be38eb99ca05051ed6d Mon Sep 17 00:00:00 2001 From: Austin Walker Date: Mon, 3 Mar 2025 12:40:14 -0500 Subject: [PATCH] chore: Clean up some outdated warning logs - Remove note about using the freemium url if you recieve a 401 - Remove "Failed to partition" error log --- .../_hooks/custom/__init__.py | 1 - .../_hooks/custom/logger_hook.py | 1 - .../_hooks/custom/suggest_defining_url.py | 32 ------------------- .../_hooks/registration.py | 3 -- 4 files changed, 37 deletions(-) delete mode 100644 src/unstructured_client/_hooks/custom/suggest_defining_url.py diff --git a/src/unstructured_client/_hooks/custom/__init__.py b/src/unstructured_client/_hooks/custom/__init__.py index 321a6b9c..8917d508 100644 --- a/src/unstructured_client/_hooks/custom/__init__.py +++ b/src/unstructured_client/_hooks/custom/__init__.py @@ -1,5 +1,4 @@ from .clean_server_url_hook import CleanServerUrlSDKInitHook from .logger_hook import LoggerHook -from .suggest_defining_url import SuggestDefiningUrlIf401AfterErrorHook from .split_pdf_hook import SplitPdfHook import logging diff --git a/src/unstructured_client/_hooks/custom/logger_hook.py b/src/unstructured_client/_hooks/custom/logger_hook.py index d1431bf0..2a583e36 100644 --- a/src/unstructured_client/_hooks/custom/logger_hook.py +++ b/src/unstructured_client/_hooks/custom/logger_hook.py @@ -78,7 +78,6 @@ def after_error( # NOTE: Even though this is an after_error method, due to split_pdf_hook logic we may get # a success here when one of the split requests was partitioned successfully return response, error - logger.error("Failed to partition the document.") if response: logger.error("Server responded with %d - %s", response.status_code, response.text) if error is not None: diff --git a/src/unstructured_client/_hooks/custom/suggest_defining_url.py b/src/unstructured_client/_hooks/custom/suggest_defining_url.py deleted file mode 100644 index d768917e..00000000 --- a/src/unstructured_client/_hooks/custom/suggest_defining_url.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import annotations - -from typing import Optional, Tuple, Union - -import httpx -import logging - -from unstructured_client._hooks.custom.common import UNSTRUCTURED_CLIENT_LOGGER_NAME -from unstructured_client._hooks.types import AfterErrorContext, AfterErrorHook - -logger = logging.getLogger(UNSTRUCTURED_CLIENT_LOGGER_NAME) - - -class SuggestDefiningUrlIf401AfterErrorHook(AfterErrorHook): - """Hook advising users to check that 'server_url' is defined if a 401 error is encountered.""" - - def warn_if_401(self, response: Optional[httpx.Response]): - """If the paid API returns 401, warn the user in case they meant to use the free api.""" - if response is not None and response.status_code == 401: - logger.warning( - "This API key is invalid against the paid API. If intending to use the free API, please initialize UnstructuredClient with `server='free-api'`." - ) - - def after_error( - self, - hook_ctx: AfterErrorContext, - response: Optional[httpx.Response], - error: Optional[Exception], - ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]: - """Concrete implementation for AfterErrorHook.""" - self.warn_if_401(response) - return response, error diff --git a/src/unstructured_client/_hooks/registration.py b/src/unstructured_client/_hooks/registration.py index f2a7fc60..22cd276d 100644 --- a/src/unstructured_client/_hooks/registration.py +++ b/src/unstructured_client/_hooks/registration.py @@ -3,7 +3,6 @@ from .custom import ( CleanServerUrlSDKInitHook, LoggerHook, - SuggestDefiningUrlIf401AfterErrorHook, SplitPdfHook, ) from .types import Hooks @@ -23,7 +22,6 @@ def init_hooks(hooks: Hooks): # Initialize custom hooks clean_server_url_hook = CleanServerUrlSDKInitHook() - suggest_defining_url_hook = SuggestDefiningUrlIf401AfterErrorHook() logger_hook = LoggerHook() split_pdf_hook = SplitPdfHook() @@ -43,6 +41,5 @@ def init_hooks(hooks: Hooks): hooks.register_after_success_hook(logger_hook) # Register After Error hooks - hooks.register_after_error_hook(suggest_defining_url_hook) hooks.register_after_error_hook(split_pdf_hook) hooks.register_after_error_hook(logger_hook)