o
    Jjg                     @  s   d Z ddlmZ ddlZ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 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dG dd deZdS )z Implement an LLM driven browser.    )annotationsN)AnyDictListOptional)
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                   @  s   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dZedded1ddZed2ddZed3d d!Zed4d#d$Zed4d%d&Z	d5d6d+d,Zd7d-d.Zed8d/d0ZdS )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	objectiveNzOptional[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   returnr   c                 C  s@   d|v rt d d|vr|d d urt|d B t B |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.r   )warningswarnr   r
   )clsr%    r*   T/var/www/html/zoom/venv/lib/python3.10/site-packages/langchain/chains/natbot/base.pyraise_deprecationC   s   zNatBotChain.raise_deprecationkwargsc                 K  s   t d)zLoad with default LLMChain.zThis 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)   r   r-   r*   r*   r+   from_defaultP   s   zNatBotChain.from_defaultr	   c                 K  s"   t |B t B }| d||d|S )zLoad from LLM.)r   r   Nr*   )r   r
   )r)   r   r   r-   r   r*   r*   r+   from_llmY   s   zNatBotChain.from_llm	List[str]c                 C  s   | j | jgS )z@Expect url and browser content.

        :meta private:
        )r   r   selfr*   r*   r+   
input_keysa   s   zNatBotChain.input_keysc                 C  s   | j gS )z0Return command.

        :meta private:
        )r   r2   r*   r*   r+   output_keysi   s   zNatBotChain.output_keysinputsDict[str, str]run_manager$Optional[CallbackManagerForChainRun]c                 C  sn   |pt  }|| j }|| j }| jj| j|d d | j|d d dd| id}|	 }|| _| j
|iS )Nd   i  )r   r   r   r   	callbacks)config)r   get_noop_managerr   r   r   invoker   r   	get_childstripr   )r3   r6   r8   _run_managerr   r   llm_cmdr*   r*   r+   _callq   s   




	
zNatBotChain._callc                 C  s   | 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:
            .. code-block:: python

                browser_content = "...."
                llm_command = natbot.run("www.google.com", browser_content)
        )r   r   r   )r3   r   r   _inputsr*   r*   r+   execute   s   zNatBotChain.executec                 C  s   dS )Nnat_bot_chainr*   r2   r*   r*   r+   _chain_type   s   zNatBotChain._chain_type)r%   r   r&   r   )r   r   r-   r   r&   r   )r   r	   r   r   r-   r   r&   r   )r&   r1   )N)r6   r7   r8   r9   r&   r7   )r   r   r   r   r&   r   )r&   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   model_configr   classmethodr,   r/   r0   propertyr4   r5   rC   rE   rG   r*   r*   r*   r+   r      s>   
 

r   )rK   
__future__r   r'   typingr   r   r   r   langchain_core._apir   langchain_core.callbacksr   langchain_core.language_modelsr	   langchain_core.output_parsersr
   langchain_core.runnablesr   pydanticr   r   langchain.chains.baser   langchain.chains.natbot.promptr   r   r*   r*   r*   r+   <module>   s$    
