
    hh                     ^    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
  G d de          ZdS )    )CallableDictIteratorOptional)Document)
BaseLoader)TensorflowDatasetsc                   r    e Zd ZdZ	 	 ddededee         deeege	f                  fdZ
d	ee	         fd
ZdS )TensorflowDatasetLoadera  Load from `TensorFlow Dataset`.

    Attributes:
        dataset_name: the name of the dataset to load
        split_name: the name of the split to load.
        load_max_docs: a limit to the number of loaded documents. Defaults to 100.
        sample_to_document_function: a function that converts a dataset sample
          into a Document

    Example:
        .. code-block:: python

            from langchain_community.document_loaders import TensorflowDatasetLoader

            def mlqaen_example_to_document(example: dict) -> Document:
                return Document(
                    page_content=decode_to_str(example["context"]),
                    metadata={
                        "id": decode_to_str(example["id"]),
                        "title": decode_to_str(example["title"]),
                        "question": decode_to_str(example["question"]),
                        "answer": decode_to_str(example["answers"]["text"][0]),
                    },
                )

            tsds_client = TensorflowDatasetLoader(
                    dataset_name="mlqa/en",
                    split_name="test",
                    load_max_docs=100,
                    sample_to_document_function=mlqaen_example_to_document,
                )

    d   Ndataset_name
split_nameload_max_docssample_to_document_functionc                     || _         || _        || _        	 || _        	 t	          | j         | j        | j        | j                  | _        dS )a{  Initialize the TensorflowDatasetLoader.

        Args:
            dataset_name: the name of the dataset to load
            split_name: the name of the split to load.
            load_max_docs: a limit to the number of loaded documents. Defaults to 100.
            sample_to_document_function: a function that converts a dataset sample
                into a Document.
        )r   r   r   r   N)r   r   r   r   r	   _tfds_client)selfr   r   r   r   s        u/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_community/document_loaders/tensorflow_datasets.py__init__z TensorflowDatasetLoader.__init__,   sc      ".)*6' 	( 	O.*,(,(H	
 
 
    returnc              #   H   K   | j                                         E d {V  d S )N)r   	lazy_load)r   s    r   r   z!TensorflowDatasetLoader.lazy_loadL   s3      $..00000000000r   )r   N)__name__
__module____qualname____doc__strr   intr   r   r   r   r   r    r   r   r   r   	   s           L (+LP
 

 
  }	

 &.hvx7G.H%I
 
 
 
@18H- 1 1 1 1 1 1r   r   N)typingr   r   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   1langchain_community.utilities.tensorflow_datasetsr	   r   r    r   r   <module>r%      s    5 5 5 5 5 5 5 5 5 5 5 5 - - - - - - @ @ @ @ @ @ P P P P P PD1 D1 D1 D1 D1j D1 D1 D1 D1 D1r   