Ë
    µŒj¡  ã                   óJ   — 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	y)é    )Ú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} t        ‰| �  «        || _        || _        d| _        | j
                  r || j
                  ¬«      | _        | j                  st        d«      ‚y# t        $ r t        d«      ‚w xY w)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       €úu/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/document_loaders/needle.pyr   zNeedleLoader.__init__+   s…   ø€ ð 	Ý.ô 	‰ÑÔØ,ˆÔØ*ˆÔØ.2ˆŒà×ÒÙ&¨t×/BÑ/BÔCˆDŒKà×!Ò!ÜÐ>Ó?Ð?ð "øô ò 	ÜØVóð ð	ús   ƒA( Á(A=c                 ó`   — | j                   €t        d«      ‚| j                  st        d«      ‚y)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   s:   € ð �;‰;ÐÜØKóð ð ×!Ò!ÜÐ>Ó?Ð?ð "ó    Úfilesc                 ó^  — 	 ddl m} | j                  «        | j                  €J d«       ‚|j                  «       D ��cg c]  \  }} |||¬«      ‘Œ }}}| j                  j                  j                  j                  | j                  |¬«       y# t        $ r t        d«      ‚w xY wc c}}w )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.)ÚnameÚurl)r   r   )
Úneedle.v1.modelsr!   r   r   r   ÚitemsÚcollectionsr   Úaddr   )r   r   r!   r#   r$   Úfiles_to_adds         r   Ú	add_fileszNeedleLoader.add_files\   s§   € ð	Ý2ð 	×ÑÔØ�{‰{Ð&ÐKÐ(KÓKÐ&àGLÇ{Á{Ä}ÔUÁ}¹)¸$À™	 t°Ö5À}ˆÑUà�‰×Ñ×%Ñ%×)Ñ)Ø×,Ñ,°Lð 	*õ 	
øô ò 	ÜØOóð ð	üó Vs   ‚B ¾B)ÂB&c                 ó`  — | j                  «        | j                  €J d«       ‚| j                  j                  j                  j	                  | j
                  «      }|D �cg c]A  }|j                  dk(  r0t        d|j                  |j                  t        |dd«      dœ¬«      ‘ŒC }}|S c c}w )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"   ÚindexedÚ Úsize)ÚsourceÚtitler.   )Úpage_contentÚmetadata)r   r   r'   r   Úlistr   Ústatusr   r$   r#   Úgetattr)r   r   ÚfileÚdocss       r   Ú_fetch_documentszNeedleLoader._fetch_documentsx   s±   € ð 	×ÑÔØ�{‰{Ð&ÐKÐ(KÓKÐ&à—‘×'Ñ'×-Ñ-×2Ñ2°4×3EÑ3EÓFˆñ ó
ñ �Ø�{‰{˜iÒ'ô Øà"Ÿh™hØ!ŸY™YÜ# D¨&°$Ó7ñöð ð 	ð 
ð ˆùò
s   Á!AB+c                 ó"   — | j                  «       S )z˜
        Loads all documents from the Needle collection.

        Returns:
            List[Document]: A list of documents from the collection.
        ©r8   r   s    r   ÚloadzNeedleLoader.load”   s   € ð ×$Ñ$Ó&Ð&r   c              #   ó@   K  — | j                  «       E d{  –—†  y7 Œ­w)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�   s   è ø€ ð ×(Ñ(Ó*×*Ò*ús   ‚–—)NN)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r   r*   r   r   r8   r;   r   r=   Ú__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   Ú<module>rH      s   ðß 1Ó 1å ;Ý -ô]+�:õ ]+r   