§
    šŠtj¡  ã                   óR   — d dl mZmZmZmZ d dlmZ d dlmZ  G d„ de¦  «        Z	dS )é    )ÚDictÚIteratorÚListÚOptional)Ú
BaseLoader)ÚDocumentc                   ó¾   ‡ — e Zd ZdZ	 	 ddee         dee         ddfˆ fd„Zdd„Zdeeef         ddfd	„Z	de
e         fd
„Zde
e         fd„Zdee         fd„Zˆ xZS )ÚNeedleLoaderaå  
    NeedleLoader is a document loader for managing documents stored in a collection.

    Setup:
        Install the `needle-python` library and set your Needle API key.

        .. code-block:: bash

            pip install needle-python
            export NEEDLE_API_KEY="your-api-key"

    Key init args:
        - `needle_api_key` (Optional[str]): API key for authenticating with Needle.
        - `collection_id` (str): Needle collection to load documents from.

    Usage:
        .. code-block:: python

            from langchain_community.document_loaders.needle import NeedleLoader

            loader = NeedleLoader(
                needle_api_key="your-api-key",
                collection_id="your-collection-id"
            )

            # Load documents
            documents = loader.load()
            for doc in documents:
                print(doc.metadata)

            # Lazy load documents
            for doc in loader.lazy_load():
                print(doc.metadata)
    NÚneedle_api_keyÚcollection_idÚreturnc                 ó"  •— 	 ddl m} n# t          $ r t          d¦  «        ‚w xY wt          ¦   «                              ¦   «          || _        || _        d| _        | j        r || j        ¬¦  «        | _        | j        st          d¦  «        ‚dS )a›  
        Initializes the NeedleLoader with API key and collection ID.

        Args:
            needle_api_key (Optional[str]): API key for authenticating with Needle.
            collection_id (Optional[str]): Identifier for the Needle collection.

        Raises:
            ImportError: If the `needle-python` library is not installed.
            ValueError: If the collection ID is not provided.
        r   )ÚNeedleClientzDPlease install with `pip install needle-python` to use NeedleLoader.N)Úapi_keyúCollection ID must be provided.)	Ú	needle.v1r   ÚImportErrorÚsuperÚ__init__r   r   ÚclientÚ
ValueError)Úselfr   r   r   Ú	__class__s       €úi/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/document_loaders/needle.pyr   zNeedleLoader.__init__+   sÆ   ø€ ð 	Ø.Ð.Ð.Ð.Ð.Ð.Ð.øÝð 	ð 	ð 	ÝØVñô ð ð	øøøõ
 	‰Œ×ÒÑÔÐØ,ˆÔØ*ˆÔØ.2ˆŒàÔð 	DØ&˜,¨tÔ/BÐCÑCÔCˆDŒKàÔ!ð 	@ÝÐ>Ñ?Ô?Ð?ð	@ð 	@ó   ƒ
 Š$c                 ó^   — | j         €t          d¦  «        ‚| j        st          d¦  «        ‚dS )zâ
        Ensures the Needle collection is set and the client is initialized.

        Raises:
            ValueError: If the Needle client is not initialized or
                        if the collection ID is missing.
        Nz9NeedleClient is not initialized. Provide a valid API key.r   )r   r   r   ©r   s    r   Ú_get_collectionzNeedleLoader._get_collectionM   sJ   € ð Œ;ÐÝØKñô ð ð Ô!ð 	@ÝÐ>Ñ?Ô?Ð?ð	@ð 	@ó    Úfilesc                 ó2  ‡— 	 ddl mŠ n# t          $ r t          d¦  «        ‚w xY w|                      ¦   «          | j        €
J d¦   «         ‚ˆfd„|                     ¦   «         D ¦   «         }| j        j        j                             | j	        |¬¦  «         dS )an  
        Adds files to the Needle collection.

        Args:
            files (Dict[str, str]): Dictionary where keys are file names and values
                                    are file URLs.

        Raises:
            ImportError: If the `needle-python` library is not installed.
            ValueError: If the collection is not properly initialized.
        r   )Ú	FileToAddz=Please install with `pip install needle-python` to add files.Nú!NeedleClient must be initialized.c                 ó0   •— g | ]\  }} ‰||¬ ¦  «        ‘ŒS ))ÚnameÚurl© )Ú.0r%   r&   r"   s      €r   ú
<listcomp>z*NeedleLoader.add_files.<locals>.<listcomp>r   s,   ø€ ÐUÐUÐU¹)¸$À˜	˜	 t°Ð5Ñ5Ô5ÐUÐUÐUr   )r   r    )
Úneedle.v1.modelsr"   r   r   r   ÚitemsÚcollectionsr    Úaddr   )r   r    Úfiles_to_addr"   s      @r   Ú	add_fileszNeedleLoader.add_files\   sÐ   ø€ ð	Ø2Ð2Ð2Ð2Ð2Ð2Ð2øÝð 	ð 	ð 	ÝØOñô ð ð	øøøð
 	×ÒÑÔÐØŒ{Ð&Ð&Ð(KÑ&Ô&Ð&àUÐUÐUÐUÀuÇ{Â{Á}Ä}ÐUÑUÔUˆàŒÔÔ%×)Ò)ØÔ,°Lð 	*ñ 	
ô 	
ð 	
ð 	
ð 	
r   c                 óº   — |                       ¦   «          | j        €
J d¦   «         ‚| j        j        j                             | j        ¦  «        }d„ |D ¦   «         }|S )a
  
        Fetches metadata for documents from the Needle collection.

        Returns:
            List[Document]: A list of documents with metadata. Content is excluded.

        Raises:
            ValueError: If the collection is not properly initialized.
        Nr#   c                 ó€   — g | ];}|j         d k    ¯t          d|j        |j        t	          |dd¦  «        dœ¬¦  «        ‘Œ<S )ÚindexedÚ ÚsizeN)ÚsourceÚtitler4   )Úpage_contentÚmetadata)Ústatusr   r&   r%   Úgetattr)r(   Úfiles     r   r)   z1NeedleLoader._fetch_documents.<locals>.<listcomp>†   sh   € ð 
ð 
ð 
ð ØŒ{˜iÒ'Ð'õ Øà"œhØ!œYÝ# D¨&°$Ñ7Ô7ðð ðñ ô ð (Ð'Ð'r   )r   r   r,   r    Úlistr   )r   r    Údocss      r   Ú_fetch_documentszNeedleLoader._fetch_documentsx   sr   € ð 	×ÒÑÔÐØŒ{Ð&Ð&Ð(KÑ&Ô&Ð&à”Ô'Ô-×2Ò2°4Ô3EÑFÔFˆð
ð 
ð ð
ñ 
ô 
ˆð ˆr   c                 ó*   — |                       ¦   «         S )z˜
        Loads all documents from the Needle collection.

        Returns:
            List[Document]: A list of documents from the collection.
        ©r>   r   s    r   ÚloadzNeedleLoader.load”   s   € ð ×$Ò$Ñ&Ô&Ð&r   c              #   ó>   K  — |                       ¦   «         E d{V —† dS )z•
        Lazily loads documents from the Needle collection.

        Yields:
            Iterator[Document]: An iterator over the documents.
        Nr@   r   s    r   Ú	lazy_loadzNeedleLoader.lazy_load�   s2   è è € ð ×(Ò(Ñ*Ô*Ð*Ð*Ð*Ð*Ð*Ð*Ð*Ð*Ð*r   )NN)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r   r/   r   r   r>   rA   r   rC   Ú__classcell__)r   s   @r   r
   r
      s$  ø€ € € € € ð!ð !ðJ )-Ø'+ð @ð  @à  œð @ð   ”}ð @ð 
ð	 @ð  @ð  @ð  @ð  @ð  @ðD@ð @ð @ð @ð
˜t C¨ Hœ~ð 
°$ð 
ð 
ð 
ð 
ð8 $ x¤.ð ð ð ð ð8'�d˜8”nð 'ð 'ð 'ð 'ð+˜8 HÔ-ð +ð +ð +ð +ð +ð +ð +ð +r   r
   N)
Útypingr   r   r   r   Ú$langchain_core.document_loaders.baser   Úlangchain_core.documentsr   r
   r'   r   r   ú<module>rM      s‹   ðØ 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø -Ð -Ð -Ð -Ð -Ð -ð]+ð ]+ð ]+ð ]+ð ]+�:ñ ]+ô ]+ð ]+ð ]+ð ]+r   