
    m
ia                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ  eddd           G d de                      ZdS )z Implement an LLM driven browser.    )annotationsN)Any)
deprecated)CallbackManagerForChainRun)BaseLanguageModel)StrOutputParser)Runnable)
ConfigDictmodel_validator)Chain)PROMPTz0.2.13zImporting NatBotChain from langchain is deprecated and will be removed in langchain 1.0. Please import from langchain_community instead: from langchain_community.chains.natbot import NatBotChain. You may need to pip install -U langchain-community.z1.0)sincemessageremovalc                  T   e Zd ZU dZded<   ded<   	 dZded<   	 d	Zded
<   dZded<   dZded<   dZ	ded<    e
dd          Z ed          ed)d                        Zed*d            Zed+d            Zed,d             Zed,d!            Z	 d-d.d&Zd/d'Zed0d(            ZdS )1NatBotChaina  Implement an LLM driven browser.

    **Security Note**: This toolkit provides code to control a web-browser.

        The web-browser can be used to navigate to:

        - Any URL (including any internal network URLs)
        - And local files

        Exercise care if exposing this chain to end-users. Control who is able to
        access and use this chain, and isolate the network access of the server
        that hosts this chain.

        See https://docs.langchain.com/oss/python/security-policy for more information.

    Example:
        ```python
        from langchain_classic.chains import NatBotChain

        natbot = NatBotChain.from_default("Buy me a new hat.")
        ```
    r	   	llm_chainstr	objectiveNzBaseLanguageModel | Nonellmurlinput_url_keybrowser_contentinput_browser_content_key previous_commandcommand
output_keyTforbid)arbitrary_types_allowedextrabefore)modevaluesdictreturnr   c                    d|v rDt          j        dd           d|vr*|d         "t          |d         z  t                      z  |d<   |S )Nr   zDirectly instantiating an NatBotChain with an llm is deprecated. Please instantiate with llm_chain argument or using the from_llm class method.   )
stacklevelr   )warningswarnr   r   )clsr$   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_classic/chains/natbot/base.py_raise_deprecationzNatBotChain._raise_deprecationD   si     F??M  	    &((VE]-F&,ve}&<?P?P&P{#    kwargsc                $    d}t          |          )zLoad with default LLMChain.zThis method is no longer implemented. Please use from_llm.model = OpenAI(temperature=0.5, best_of=10, n=3, max_tokens=50)For example, NatBotChain.from_llm(model, objective))NotImplementedError)r,   r   r0   msgs       r-   from_defaultzNatBotChain.from_defaultR   s    B 	
 "#&&&r/   r   c                J    t           |z  t                      z  } | d||d|S )zLoad from LLM.)r   r    )r   r   )r,   r   r   r0   r   s        r-   from_llmzNatBotChain.from_llm\   s5     SL?#4#44	sFY)FFvFFFr/   	list[str]c                    | j         | j        gS )zExpect url and browser content.)r   r   selfs    r-   
input_keyszNatBotChain.input_keysg   s     "D$BCCr/   c                    | j         gS )zReturn command.)r   r:   s    r-   output_keyszNatBotChain.output_keysl   s       r/   inputsdict[str, str]run_manager!CallbackManagerForChainRun | Nonec                F   |pt          j                    }|| j                 }|| j                 }| j                            | j        |d d         | j        |d d         dd|                                i          }|	                                }|| _        | j
        |iS )Nd   i  )r   r   r   r   	callbacks)config)r   get_noop_managerr   r   r   invoker   r   	get_childstripr   )r;   r?   rA   _run_managerr   r   llm_cmds          r-   _callzNatBotChain._callq   s    
 #S&@&Q&S&ST'( !?@.''!^4C4y$($9#25D5#9	   !7!7!9!9: ( 
 
 --// '))r/   c                N    | j         || j        |i} | |          | j                 S )a  Figure out next browser command to run.

        Args:
            url: URL of the site currently on.
            browser_content: Content of the page as currently displayed by the browser.

        Returns:
            Next browser command to run.

        Example:
            ```python
            browser_content = "...."
            llm_command = natbot.run("www.google.com", browser_content)
            ```
        )r   r   r   )r;   r   r   _inputss       r-   executezNatBotChain.execute   s2    " *O
 tG}}T_--r/   c                    dS )Nnat_bot_chainr6   r:   s    r-   _chain_typezNatBotChain._chain_type   s    r/   )r$   r%   r&   r   )r   r   r0   r   r&   r   )r   r   r   r   r0   r   r&   r   )r&   r8   )N)r?   r@   rA   rB   r&   r@   )r   r   r   r   r&   r   )r&   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r
   model_configr   classmethodr.   r4   r7   propertyr<   r>   rM   rP   rS   r6   r/   r-   r   r      s         . NNN:$(C((((*M%66666J: $  L
 _(###
 
 
 [ $#
 ' ' ' [' G G G [G D D D XD ! ! ! X! :>* * * * **. . . .,    X  r/   r   )rW   
__future__r   r*   typingr   langchain_core._apir   langchain_core.callbacksr   langchain_core.language_modelsr   langchain_core.output_parsersr   langchain_core.runnablesr	   pydanticr
   r   langchain_classic.chains.baser   &langchain_classic.chains.natbot.promptr   r   r6   r/   r-   <module>rf      s9   & & " " " " " "        * * * * * * ? ? ? ? ? ? < < < < < < 9 9 9 9 9 9 - - - - - - 0 0 0 0 0 0 0 0 / / / / / / 9 9 9 9 9 9 
	>
 	 	 	A A A A A% A A	 	A A Ar/   