
    Min'                        S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	J
r
  SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJr  SSKJrJr  \" 5       r\     SS\S\\\4   S\	\   S\	\   S\	\
\ \RB                  4      S\	\   S\	\\\4      S\4S jj5       r"\     SS\S\\\4   S\	\   S\	\   S\	\
\ \RB                  4      S\	\   S\	\\\4      S\
\\\\\4   4   4S jj5       r#g)z 
Main OCR function for LiteLLM.
    N)partial)Any	CoroutineDictOptionalUnion)verbose_logger)request_timeout)Logging)BaseOCRConfigOCRResponse)BaseLLMHTTPHandler)GenericLiteLLMParams)ProviderConfigManagerclientmodeldocumentapi_keyapi_basetimeoutcustom_llm_providerextra_headersreturnc                   #    [        5       n [        R                  " 5       n	SUS'   Uc  [        R                  " XS9u  p  n
[        [        4U UUUUUUS.UD6n[        R                  " 5       n[        UR                  U5      nU	R                  SU5      I Sh  vN n[        R                  " U5      (       a  UI Sh  vN nOUnUc  [        SU 35      eU$  N? N! [         a  n[        R                  " U UUUUS9eSnAff = f7f)a  
Async OCR function.

Args:
    model: Model name (e.g., "mistral/mistral-ocr-latest")
    document: Document to process in Mistral format:
        {"type": "document_url", "document_url": "https://..."} for PDFs/docs or
        {"type": "image_url", "image_url": "https://..."} for images
    api_key: Optional API key
    api_base: Optional API base URL
    timeout: Optional timeout
    custom_llm_provider: Optional custom LLM provider
    extra_headers: Optional extra headers
    **kwargs: Additional parameters (e.g., include_image_base64, pages, image_limit)
    
Returns:
    OCRResponse in Mistral OCR format with pages, model, usage_info, etc.
    
Example:
    ```python
    import litellm
    
    # OCR with PDF
    response = await litellm.aocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "document_url",
            "document_url": "https://arxiv.org/pdf/2201.04234"
        },
        include_image_base64=True
    )
    
    # OCR with image
    response = await litellm.aocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "image_url",
            "image_url": "https://example.com/image.png"
        }
    )
    
    # OCR with base64 encoded PDF
    response = await litellm.aocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "document_url",
            "document_url": f"data:application/pdf;base64,{base64_pdf}"
        }
    )
    ```
TaocrN)r   r   )r   r   r   r   r   r   r   z2Got an unexpected None response from the OCR API: r   r   original_exceptioncompletion_kwargsextra_kwargs)localsasyncioget_event_looplitellmget_llm_providerr   ocrcontextvarscopy_contextrunrun_in_executoriscoroutine
ValueError	Exceptionexception_type)r   r   r   r   r   r   r   kwargs
local_varsloop_funcctxfunc_with_contextinit_responseresponsees                    j/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/litellm/ocr/main.pyr   r      s7    | J,
%%'v &+2+C+C,(AAq 

 3'

 

 &&(#CGGT2"2249JKK}--**H$HDXJO   L +  
$$ 3 (
 	

sM   D	BC C$C  CC D	C C 
D)DDD	c                    [        5       n UR                  S5      n	UR                  SS5      n
UR                  SS5      SL n[        U[        5      (       d  [        S[        U5       35      eUR                  S5      nUS	;  a  [        S
U S35      e[        R                  " U UUUS9u  ppU(       a  UnU(       a  Un[        R                  " U [        R                  " U5      S9nUc  [        SU 35      e[        R                  " SU  SU 35        [        S0 UD6nUR                  U S9n0 nU H  nUU;   d  M  UR                  U5      UU'   M!     UR!                  U0 U S9n[        R                  " SU 35        U	R#                  U UU
US.US9  [$        R'                  U UUU=(       d    [(        U	UUUUUU[	        U5      S9nU$ ! [*         a  n[        R,                  " U UUUUS9eSnAff = f)a  
Synchronous OCR function.

Args:
    model: Model name (e.g., "mistral/mistral-ocr-latest")
    document: Document to process in Mistral format:
        {"type": "document_url", "document_url": "https://..."} for PDFs/docs or
        {"type": "image_url", "image_url": "https://..."} for images
    api_key: Optional API key
    api_base: Optional API base URL
    timeout: Optional timeout
    custom_llm_provider: Optional custom LLM provider
    extra_headers: Optional extra headers
    **kwargs: Additional parameters (e.g., include_image_base64, pages, image_limit)
    
Returns:
    OCRResponse in Mistral OCR format with pages, model, usage_info, etc.
    
Example:
    ```python
    import litellm
    
    # OCR with PDF
    response = litellm.ocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "document_url",
            "document_url": "https://arxiv.org/pdf/2201.04234"
        },
        include_image_base64=True
    )
    
    # OCR with image
    response = litellm.ocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "image_url",
            "image_url": "https://example.com/image.png"
        }
    )
    
    # OCR with base64 encoded PDF
    response = litellm.ocr(
        model="mistral/mistral-ocr-latest",
        document={
            "type": "document_url",
            "document_url": f"data:application/pdf;base64,{base64_pdf}"
        }
    )
    
    # Access pages
    for page in response.pages:
        print(f"Page {page.index}: {page.markdown}")
    ```
litellm_logging_objlitellm_call_idNr   FTz7document must be a dict with 'type' and URL field, got type)document_url	image_urlzInvalid document type: z'. Must be 'document_url' or 'image_url')r   r   r   r   )r   providerz#OCR is not supported for provider: zOCR call - model: z, provider: )r   )non_default_paramsoptional_paramsr   z#OCR optional_params after mapping: )r;   r   )r   rA   litellm_paramsr   )r   r   rA   r   logging_objr   r   r   r   headersprovider_configrB   r    )r    popget
isinstancedictr+   r<   r#   r$   r   get_provider_ocr_configLlmProvidersr	   debugr   get_supported_ocr_paramsmap_ocr_paramsupdate_environment_variablesbase_llm_http_handlerr%   r
   r,   r-   )r   r   r   r   r   r   r   r.   r/   r:   r;   	_is_asyncdoc_typedynamic_api_keydynamic_api_baseocr_provider_configrB   supported_paramsr@   paramrA   r6   r7   s                          r8   r%   r%      ss   D Jc
17<Q1R)/4Et)LJJvu-5	 (D))VW[\dWeVfghh<<'886xj@ghii $$$7!	 	FO %G'H "99 --.AB 	 &56I5JK  	 |4G3HI	

 .77 /GGeGT%E,2JJu,="5) &
 .<<1 = 
 	B?BSTU 	88+#2$ !4 	9 	
 ),,+.+ 3!// - 
  
$$ 3 (
 	

s   D0G  BG 
G4G//G4)NNNNN)$__doc__r!   r&   	functoolsr   typingr   r   r   r   r   httpxr#   litellm._loggingr	   litellm.constantsr
   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObj(litellm.llms.base_llm.ocr.transformationr   r   *litellm.llms.custom_httpx.llm_http_handlerr   litellm.types.routerr   litellm.utilsr   r   rQ   strfloatTimeoutr   r%   rF       r8   <module>ri      s      8 8   + - S O I 5 7 +,   ""59)-.2j
j
38nj
 c]j
 sm	j

 eE5==012j
 "#j
 DcN+j
 j
 j
Z  ""59)-.2e
e
38ne
 c]e
 sm	e

 eE5==012e
 "#e
 DcN+e
 ;	#sK"7889e
 e
rh   