a
    bg                     @  sx   d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ erdd dlmZ G dd	 d	e
Zd
S )    )annotations)TYPE_CHECKINGIteratorListOptional)Document)
BaseLoader)Blob)!AzureAIDocumentIntelligenceParser)TokenCredentialc                   @  sJ   e Zd ZdZddddddddddddd	d
ddddZddddZdS )!AzureAIDocumentIntelligenceLoaderz,Load a PDF with Azure Document Intelligence.Nprebuilt-layoutmarkdown)analysis_featuresazure_credentialstrzOptional[str]zOptional[bytes]zOptional[List[str]]zOptional['TokenCredential']None)api_endpointapi_key	file_pathurl_pathbytes_sourceapi_version	api_modelmoder   r   returnc	             	   C  s~   |dus |dus |dus J d|dus8|
dus8J d|du sP|
du sPJ d|| _ || _|| _t||||||	|
d| _dS )a
  
        Initialize the object for file processing with Azure Document Intelligence
        (formerly Form Recognizer).

        This constructor initializes a AzureAIDocumentIntelligenceParser object to be
        used for parsing files using the Azure Document Intelligence API. The load
        method generates Documents whose content representations are determined by the
        mode parameter.

        Parameters:
        -----------
        api_endpoint: str
            The API endpoint to use for DocumentIntelligenceClient construction.
        api_key: str
            The API key to use for DocumentIntelligenceClient construction.
        file_path : Optional[str]
            The path to the file that needs to be loaded.
            Either file_path, url_path or bytes_source must be specified.
        url_path : Optional[str]
            The URL to the file that needs to be loaded.
            Either file_path, url_path or bytes_source must be specified.
        bytes_source : Optional[bytes]
            The bytes array of the file that needs to be loaded.
            Either file_path, url_path or bytes_source must be specified.
        api_version: Optional[str]
            The API version for DocumentIntelligenceClient. Setting None to use
            the default value from `azure-ai-documentintelligence` package.
        api_model: str
            Unique document model name. Default value is "prebuilt-layout".
            Note that overriding this default value may result in unsupported
            behavior.
        mode: Optional[str]
            The type of content representation of the generated Documents.
            Use either "single", "page", or "markdown". Default value is "markdown".
        analysis_features: Optional[List[str]]
            List of optional analysis features, each feature should be passed
            as a str that conforms to the enum `DocumentAnalysisFeature` in
            `azure-ai-documentintelligence` package. Default value is None.
        azure_credential: Optional[TokenCredential]
            The credentials to use for DocumentIntelligenceClient construction, when
            using credentials other than api_key (like AD).

        Examples:
        ---------
        >>> obj = AzureAIDocumentIntelligenceLoader(
        ...     file_path="path/to/file",
        ...     api_endpoint="https://endpoint.azure.com",
        ...     api_key="APIKEY",
        ...     api_version="2023-10-31-preview",
        ...     api_model="prebuilt-layout",
        ...     mode="markdown"
        ... )
        Nz4file_path, url_path or bytes_source must be providedz4Either api_key or azure_credential must be provided.z;Only one of api_key or azure_credential should be provided.)r   r   r   r   r   r   r   )r   r   r   r
   parser)selfr   r   r   r   r   r   r   r   r   r    r   /var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/doc_intelligence.py__init__   s@    Ez*AzureAIDocumentIntelligenceLoader.__init__zIterator[Document])r   c                 c  sv   | j dur*t| j }| j|E dH  nH| jdurJ| j| jE dH  n(| jdurj| j| jE dH  nt	ddS )z Lazy load the document as pages.NzNo data source provided.)
r   r	   	from_pathr   parser   	parse_urlr   Zparse_bytes
ValueError)r   Zblobr   r   r   	lazy_loadr   s    


z+AzureAIDocumentIntelligenceLoader.lazy_load)NNNNNr   r   )__name__
__module____qualname____doc__r    r%   r   r   r   r   r      s          &^r   N)
__future__r   typingr   r   r   r   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z1langchain_community.document_loaders.blob_loadersr	   Z,langchain_community.document_loaders.parsersr
   Zazure.core.credentialsr   r   r   r   r   r   <module>   s   