
    i/                        d Z ddlmZmZmZmZmZmZ ddlZddl	m
Z
 ddlmZ ddlmZ erddlmZ neZeeef   Z G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d      Zy)z(
Base OCR transformation configuration.
    )TYPE_CHECKINGAnyDictListOptionalUnionN)PrivateAttrBaseLLMException)LiteLLMPydanticObjectBase)Loggingc                   N    e Zd ZU dZdZee   ed<   dZee   ed<   dZ	ee   ed<   y)OCRPageDimensionsz"Page dimensions from OCR response.Ndpiheightwidth)
__name__
__module____qualname____doc__r   r   int__annotations__r   r        y/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/base_llm/ocr/transformation.pyr   r      s/    ,C# FHSM E8C=r   r   c                   L    e Zd ZU dZdZee   ed<   dZee	ee
f      ed<   ddiZy)OCRPageImagezImage extracted from OCR page.Nimage_base64bboxextraallow)r   r   r   r   r   r   strr   r   r   r   model_configr   r   r   r   r       s4    ("&L(3-&%)D(4S>
")W%Lr   r   c                   \    e Zd ZU dZeed<   eed<   dZee	e
      ed<   dZee   ed<   ddiZy)	OCRPagezSingle page from OCR response.indexmarkdownNimages
dimensionsr    r!   )r   r   r   r   r   r   r"   r(   r   r   r   r)   r   r#   r   r   r   r%   r%   )   s=    (JM+/FHT,'(/.2J*+2W%Lr   r%   c                   B    e Zd ZU dZdZee   ed<   dZee   ed<   ddiZ	y)OCRUsageInfoz$Usage information from OCR response.Npages_processeddoc_size_bytesr    r!   )
r   r   r   r   r,   r   r   r   r-   r#   r   r   r   r+   r+   4   s+    .%)OXc])$(NHSM(W%Lr   r+   c                       e Zd ZU dZee   ed<   eed<   dZe	e
   ed<   dZe	e   ed<   dZeed<   d	d
iZ ee      Zeed<   y)OCRResponsez
    Standard OCR response format.
    Standardized to Mistral OCR format - other providers should transform to this format.
    pagesmodelNdocument_annotation
usage_infoocrobjectr    r!   )default_factory_hidden_params)r   r   r   r   r   r%   r   r"   r2   r   r   r3   r+   r5   r#   r	   dictr7   r   r   r   r/   r/   =   s[    
 =J)-#-)-J&-FCW%L 't<ND<r   r/   c                   N    e Zd ZU dZdZeeeef      e	d<   dZ
eeeef      e	d<   y)OCRRequestDatazOCR request data structure.Ndatafiles)r   r   r   r   r;   r   r   r   bytesr   r<   r"   r   r   r   r   r:   r:   O   s4    %)-D(5u%
&-&*E8DcN#*r   r:   c                   N   e Zd ZdZddZdedefdZdedededefd	Z		 	 	 dd
e
dedee   dee   dee   de
fdZ	 ddee   dededee   def
dZdededed
edef
dZdededed
edef
dZdedej&                  dedefdZdedej&                  dedefdZdeded
edefdZy)BaseOCRConfigzc
    Base configuration for OCR transformations.
    Handles provider-agnostic OCR operations.
    returnNc                      y Nr   )selfs    r   __init__zBaseOCRConfig.__init__\   s    r   r1   c                     g S )z
        Get supported OCR parameters for this provider.
        Override this method in provider-specific implementations.
        r   )rC   r1   s     r   get_supported_ocr_paramsz&BaseOCRConfig.get_supported_ocr_params_   s	    
 	r   non_default_paramsoptional_paramsc                     |S )z3Map OCR parameters to provider-specific parameters.r   )rC   rG   rH   r1   s       r   map_ocr_paramszBaseOCRConfig.map_ocr_paramsf   s
     r   headersapi_keyapi_baselitellm_paramsc                     |S )zq
        Validate environment and return headers.
        Override in provider-specific implementations.
        r   )rC   rK   r1   rL   rM   rN   kwargss          r   validate_environmentz"BaseOCRConfig.validate_environmento   s	     r   c                     t        d      )zk
        Get complete URL for OCR endpoint.
        Override in provider-specific implementations.
        z0get_complete_url must be implemented by providerNotImplementedError)rC   rM   r1   rH   rN   rP   s         r   get_complete_urlzBaseOCRConfig.get_complete_url~   s     ""TUUr   documentc                     t        d      )a  
        Transform OCR request to provider-specific format.
        Override in provider-specific implementations.

        Note: By the time this method is called, any file-type documents have already
        been converted to document_url/image_url format with base64 data URIs by
        the preprocessing in litellm/ocr/main.py.

        Args:
            model: Model name
            document: Document to process - always a dict with type="document_url" or type="image_url"
            optional_params: Optional parameters for the request
            headers: Request headers

        Returns:
            OCRRequestData with data and files fields
        z5transform_ocr_request must be implemented by providerrS   rC   r1   rV   rH   rK   rP   s         r   transform_ocr_requestz#BaseOCRConfig.transform_ocr_request   s    2 "C
 	
r   c                 8   K    | j                   d||||d|S w)aU  
        Async transform OCR request to provider-specific format.
        Optional method - providers can override if they need async transformations
        (e.g., Azure AI for URL-to-base64 conversion).

        Default implementation falls back to sync transform_ocr_request.

        Args:
            model: Model name
            document: Document to process (Mistral format dict, or file path, bytes, etc.)
            optional_params: Optional parameters for the request
            headers: Request headers

        Returns:
            OCRRequestData with data and files fields
        )r1   rV   rH   rK   r   )rY   rX   s         r   async_transform_ocr_requestz)BaseOCRConfig.async_transform_ocr_request   s8     2 *t)) 
+	

 
 	
s   raw_responselogging_objc                     t        d      )z
        Transform provider-specific OCR response to standard format.
        Override in provider-specific implementations.
        z6transform_ocr_response must be implemented by providerrS   rC   r1   r\   r]   rP   s        r   transform_ocr_responsez$BaseOCRConfig.transform_ocr_response   s     "D
 	
r   c                 6   K    | j                   d|||d|S w)a  
        Async transform provider-specific OCR response to standard format.
        Optional method - providers can override if they need async transformations
        (e.g., Azure Document Intelligence for async operation polling).

        Default implementation falls back to sync transform_ocr_response.

        Args:
            model: Model name
            raw_response: Raw HTTP response
            logging_obj: Logging object

        Returns:
            OCRResponse in standard format
        )r1   r\   r]   r   )r`   r_   s        r   async_transform_ocr_responsez*BaseOCRConfig.async_transform_ocr_response   s5     . +t** 
%#
 	
 	
s   error_messagestatus_codec                     t        |||      S )z-Get appropriate error class for the provider.)rd   messagerK   r
   )rC   rc   rd   rK   s       r   get_error_classzBaseOCRConfig.get_error_class   s      #!
 	
r   )r@   N)NNNrB   )r   r   r   r   rD   r"   listrF   r8   rJ   r   r   rQ   rU   DocumentTyper:   rY   r[   httpxResponseLiteLLMLoggingObjr/   r`   rb   r   	Exceptionrg   r   r   r   r?   r?   V   s   
c d    	
 
 "&"&)-  #	
 3- ! 
( *.V3-V V 	V
 !V 
V

 
 	

 
 

:

 
 	

 
 

B

 nn
 '	
 



 nn
 '	
 

<

 
 	

 

r   r?   )r   typingr   r   r   r   r   r   rj   pydanticr	   )litellm.llms.base_llm.chat.transformationr   litellm.types.llms.baser   *litellm.litellm_core_utils.litellm_loggingr   rl   r"   ri   r   r   r%   r+   r/   r:   r?   r   r   r   <module>rs      s    C B    F =W CH~ 1  &, &&' &&, &=+ =$+. +l
 l
r   