HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain/chains/natbot/__pycache__/base.cpython-310.pyc
o

���g9�@s�dZddlmZddlZddlmZmZmZmZddl	m
Z
ddlmZddl
mZddl
mZdd	lmZdd
lmZddlmZddlmZmZdd
lmZddlmZe
dddd�Gdd�de��Ze��dS)z Implement an LLM driven browser.�)�annotationsN)�Any�Dict�List�Optional)�
deprecated)�	BaseCache)�CallbackManagerForChainRun)�	Callbacks)�BaseLanguageModel)�StrOutputParser)�Runnable)�
ConfigDict�model_validator)�Chain)�PROMPTz0.2.13z�Importing 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.z1.0)�since�message�removalc@s�eZdZUdZded<ded<	dZded<	d	Zded
<dZded<d
Zded<dZ	ded<e
ddd�Zedd�e
d1dd���Ze
d2dd��Ze
d3d d!��Zed4d#d$��Zed4d%d&��Z	d5d6d+d,�Zd7d-d.�Zed8d/d0��ZdS)9�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://python.langchain.com/docs/security for more information.

    Example:
        .. code-block:: python

            from langchain.chains import NatBotChain
            natbot = NatBotChain.from_default("Buy me a new hat.")
    r
�	llm_chain�str�	objectiveNzOptional[BaseLanguageModel]�llm�url�
input_url_key�browser_content�input_browser_content_key��previous_command�command�
output_keyT�forbid)�arbitrary_types_allowed�extra�before)�mode�valuesr�returnrcCs@d|vrt�d�d|vr|ddurt|dBt�B|d<|S)Nrz�Directly instantiating an NatBotChain with an llm is deprecated. Please instantiate with llm_chain argument or using the from_llm class method.r)�warnings�warnrr)�clsr'�r,�G/usr/local/lib/python3.10/dist-packages/langchain/chains/natbot/base.py�raise_deprecationEs�zNatBotChain.raise_deprecation�kwargscKstd��)zLoad with default LLMChain.z�This method is no longer implemented. Please use from_llm.llm = OpenAI(temperature=0.5, best_of=10, n=3, max_tokens=50)For example, NatBotChain.from_llm(llm, objective))�NotImplementedError)r+rr/r,r,r-�from_defaultRs�zNatBotChain.from_defaultrcKs"t|Bt�B}|d||d�|��S)zLoad from LLM.)rrNr,)rr)r+rrr/rr,r,r-�from_llm[szNatBotChain.from_llm�	List[str]cCs|j|jgS)z@Expect url and browser content.

        :meta private:
        )rr��selfr,r,r-�
input_keyscszNatBotChain.input_keyscCs|jgS)z0Return command.

        :meta private:
        )r!r4r,r,r-�output_keyskszNatBotChain.output_keys�inputs�Dict[str, str]�run_manager�$Optional[CallbackManagerForChainRun]cCsn|pt��}||j}||j}|jj|j|dd�|j|dd�d�d|��id�}|�	�}||_|j
|iS)N�di�)rrrr�	callbacks)�config)r	�get_noop_managerrrr�invokerr�	get_child�stripr!)r5r8r:�_run_managerrr�llm_cmdr,r,r-�_callss



�
�	
zNatBotChain._callcCs|j||j|i}||�|jS)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:
            .. code-block:: python

                browser_content = "...."
                llm_command = natbot.run("www.google.com", browser_content)
        )rrr!)r5rr�_inputsr,r,r-�execute�s�zNatBotChain.executecCsdS)N�
nat_bot_chainr,r4r,r,r-�_chain_type�szNatBotChain._chain_type)r'rr(r)rrr/rr(r)rrrrr/rr(r)r(r3)N)r8r9r:r;r(r9)rrrrr(r)r(r)�__name__�
__module__�__qualname__�__doc__�__annotations__rrrrr!r�model_configr�classmethodr.r1r2�propertyr6r7rErGrIr,r,r,r-rs>
�
�
r)rM�
__future__rr)�typingrrrr�langchain_core._apir�langchain_core.cachesr�langchain_core.callbacksr	r
�langchain_core.language_modelsr�langchain_core.output_parsersr�langchain_core.runnablesr
�pydanticrr�langchain.chains.baser�langchain.chains.natbot.promptrr�
model_rebuildr,r,r,r-�<module>s,�