o
    Zh                      @   sp   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
mZ d dlmZ edddd	G d
d dee
ZdS )    )AnyCallableDictList)
deprecated)Document)	BaseModelmodel_validator)
BaseLoaderz0.3.18zThis class is deprecated and will be removed in a future version. You can swap to using the `ApifyDatasetLoader` implementation in `langchain_apify` package. See <https://github.com/apify/langchain-apify>z"langchain_apify.ApifyDatasetLoader)ZsincemessageZalternative_importc                       s   e Zd ZU dZeed< 	 eed< 	 eege	f ed< 	 dedeege	f f fddZ
edded	ed
efddZd
ee	 fddZ  ZS )ApifyDatasetLoadera  Load datasets from `Apify` web scraping, crawling, and data extraction platform.

    For details, see https://docs.apify.com/platform/integrations/langchain

    Example:
        .. code-block:: python

            from langchain_community.document_loaders import ApifyDatasetLoader
            from langchain_core.documents import Document

            loader = ApifyDatasetLoader(
                dataset_id="YOUR-DATASET-ID",
                dataset_mapping_function=lambda dataset_item: Document(
                    page_content=dataset_item["text"], metadata={"source": dataset_item["url"]}
                ),
            )
            documents = loader.load()
    apify_client
dataset_iddataset_mapping_functionc                    s   t  j||d dS )ar  Initialize the loader with an Apify dataset ID and a mapping function.

        Args:
            dataset_id (str): The ID of the dataset on the Apify platform.
            dataset_mapping_function (Callable): A function that takes a single
                dictionary (an Apify dataset item) and converts it to an instance
                of the Document class.
        )r   r   N)super__init__)selfr   r   	__class__ i/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/document_loaders/apify_dataset.pyr   0   s   
zApifyDatasetLoader.__init__before)modevaluesreturnc                 C   sZ   z!ddl m} | }t|jd }r|jd  d7  < ||d< W |S  ty,   tdw )zYValidate environment.

        Args:
            values: The values to validate.
        r   )ApifyClienthttpx_clientz
user-agentz; Origin/langchainr   z`Could not import apify-client Python package. Please install it with `pip install apify-client`.)r   r   getattrhttp_clientheadersImportError)clsr   r   clientr   r   r   r   validate_environment?   s   	
z'ApifyDatasetLoader.validate_environmentc                 C   s(   | j | jjddj}tt| j|S )zLoad documents.T)clean)r   Zdatasetr   Z
list_itemsitemslistmapr   )r   Zdataset_itemsr   r   r   loadX   s   zApifyDatasetLoader.load)__name__
__module____qualname____doc__r   __annotations__strr   r   r   r   r	   classmethodr#   r   r(   __classcell__r   r   r   r   r   
   s"   
 r   N)typingr   r   r   r   Zlangchain_core._apir   Zlangchain_core.documentsr   Zpydanticr   r	   Z)langchain_community.document_loaders.baser
   r   r   r   r   r   <module>   s    
