
    
iw$                         d dl mZ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mZ erd dlmZ  eddd	
           G d de                      ZdS )    )TYPE_CHECKINGAnyCallableDictOptional)
deprecated)Document)get_from_dict_or_env)	BaseModelmodel_validatorApifyDatasetLoaderz0.3.18zThis class is deprecated and will be removed in a future version. You can swap to using the `ApifyWrapper` implementation in `langchain_apify` package. See <https://github.com/apify/langchain-apify>zlangchain_apify.ApifyWrapper)sincemessagealternative_importc                      e Zd ZU dZeed<   eed<   dZee         ed<    e	d          e
ded	efd
                        Zdddddededeegef         dee         dee         dee         d	dfdZdddddededeegef         dee         dee         dee         d	dfdZdddddededeegef         dee         dee         dee         d	dfdZdddddededeegef         dee         dee         dee         d	dfdZdS )ApifyWrapperzWrapper around Apify.
    To use, you should have the ``apify-client`` python package installed,
    and the environment variable ``APIFY_API_TOKEN`` set with your API key, or pass
    `apify_api_token` as a named parameter to the constructor.
    apify_clientapify_client_asyncNapify_api_tokenbefore)modevaluesreturnc                 f   t          |dd          }	 ddlm}m}  ||          }t	          |j        d          x}r|j        dxx         dz  cc<    ||          }t	          |j        d          x}r|j        dxx         dz  cc<   ||d	<   ||d
<   n# t          $ r t          d          w xY w|S )zValidate environment.
        Validate that an Apify API token is set and the apify-client
        Python package exists in the current environment.
        r   APIFY_API_TOKENr   )ApifyClientApifyClientAsynchttpx_clientz
user-agentz; Origin/langchainhttpx_async_clientr   r   z`Could not import apify-client Python package. Please install it with `pip install apify-client`.)r
   r   r   r   getattrhttp_clientheadersImportError)	clsr   r   r   r   clientr   async_clientr    s	            C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_community/utilities/apify.pyvalidate_environmentz!ApifyWrapper.validate_environment!   s+    /%'8
 
	BBBBBBBB [11F&v'9>JJJ| K$\2226JJ222++O<<L%,(*>& & ! Q #*<888<PP888%+F>"+7F'(( 	 	 	E  	 s   B B B.)buildmemory_mbytestimeout_secsactor_id	run_inputdataset_mapping_functionr*   r+   r,   r   c                    ddl m} | j                            |                              ||||          } ||d         |          S )a  Run an Actor on the Apify platform and wait for results to be ready.
        Args:
            actor_id (str): The ID or name of the Actor on the Apify platform.
            run_input (Dict): The input object of the Actor that you're trying to run.
            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.
            build (str, optional): Optionally specifies the actor build to run.
                It can be either a build tag or build number.
            memory_mbytes (int, optional): Optional memory limit for the run,
                in megabytes.
            timeout_secs (int, optional): Optional timeout for the run, in seconds.
        Returns:
            ApifyDatasetLoader: A loader that will fetch the records from the
                Actor run's default dataset.
        r   r   r.   r*   r+   r,   defaultDatasetId
dataset_idr/   )$langchain_community.document_loadersr   r   actorcall	selfr-   r.   r/   r*   r+   r,   r   
actor_calls	            r(   
call_actorzApifyWrapper.call_actorC   sv    4 	LKKKKK&,,X66;;'%	 < 
 

 "!!"45%=
 
 
 	
    c                   K   ddl m} | j                            |                              ||||           d{V } ||d         |          S )a  Run an Actor on the Apify platform and wait for results to be ready.
        Args:
            actor_id (str): The ID or name of the Actor on the Apify platform.
            run_input (Dict): The input object of the Actor that you're trying to run.
            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.
            build (str, optional): Optionally specifies the actor build to run.
                It can be either a build tag or build number.
            memory_mbytes (int, optional): Optional memory limit for the run,
                in megabytes.
            timeout_secs (int, optional): Optional timeout for the run, in seconds.
        Returns:
            ApifyDatasetLoader: A loader that will fetch the records from the
                Actor run's default dataset.
        r   r   r1   Nr2   r3   )r5   r   r   r6   r7   r8   s	            r(   acall_actorzApifyWrapper.acall_actork   s      4 	LKKKKK288BBGG'%	 H 
 
 
 
 
 
 
 

 "!!"45%=
 
 
 	
r<   task_id
task_inputc                    ddl m} | j                            |                              ||||          } ||d         |          S )  Run a saved Actor task on Apify and wait for results to be ready.
        Args:
            task_id (str): The ID or name of the task on the Apify platform.
            task_input (Dict): The input object of the task that you're trying to run.
                Overrides the task's saved input.
            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.
            build (str, optional): Optionally specifies the actor build to run.
                It can be either a build tag or build number.
            memory_mbytes (int, optional): Optional memory limit for the run,
                in megabytes.
            timeout_secs (int, optional): Optional timeout for the run, in seconds.
        Returns:
            ApifyDatasetLoader: A loader that will fetch the records from the
                task run's default dataset.
        r   r   r@   r*   r+   r,   r2   r3   )r5   r   r   taskr7   	r9   r?   r@   r/   r*   r+   r,   r   	task_calls	            r(   call_actor_taskzApifyWrapper.call_actor_task   sv    6 	LKKKKK%**73388!'%	 9 
 
	 "! !34%=
 
 
 	
r<   c                   K   ddl m} | j                            |                              ||||           d{V } ||d         |          S )rB   r   r   rC   Nr2   r3   )r5   r   r   rD   r7   rE   s	            r(   acall_actor_taskzApifyWrapper.acall_actor_task   s      6 	LKKKKK166w??DD!'%	 E 
 
 
 
 
 
 
 
	 "! !34%=
 
 
 	
r<   )__name__
__module____qualname____doc__r   __annotations__r   r   strr   classmethodr   r)   r   r	   intr;   r>   rG   rI    r<   r(   r   r      s          %)OXc])))_(###$ 3    [ $#L  $'+&*&
 &
 &
&
 &
 #+D68+;"<	&
 }&
  }&
 sm&
 
&
 &
 &
 &
\  $'+&*&
 &
 &
&
 &
 #+D68+;"<	&
 }&
  }&
 sm&
 
&
 &
 &
 &
\  $'+&*'
 '
 '
'
 '
 #+D68+;"<	'
 }'
  }'
 sm'
 
'
 '
 '
 '
^  $'+&*'
 '
 '
'
 '
 #+D68+;"<	'
 }'
  }'
 sm'
 
'
 '
 '
 '
 '
 '
r<   r   N)typingr   r   r   r   r   langchain_core._apir   langchain_core.documentsr	   langchain_core.utilsr
   pydanticr   r   r5   r   r   rR   r<   r(   <module>rX      s   ? ? ? ? ? ? ? ? ? ? ? ? ? ? * * * * * * - - - - - - 5 5 5 5 5 5 / / / / / / / / HGGGGGG 
	9
 6	 	 	M
 M
 M
 M
 M
9 M
 M
	 	M
 M
 M
r<   