
    @h                        S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  \" SSSS9 " S S\5      5       rg)z Implement an LLM driven browser.    )annotationsN)Any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                  D   \ rS rSr% SrS\S'   S\S'    SrS\S	'    S
rS\S'   SrS\S'   Sr	S\S'   Sr
S\S'   \" SSS9r\" SS9\S S j5       5       r\S!S j5       r\        S"S j5       r\S#S j5       r\S#S j5       r S$     S%S jjrS&S jr\S'S j5       rSrg)(NatBotChain   a|  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)modec                    SU;   a;  [         R                  " SSS9  SU;  a   US   b  [        US   -  [        5       -  US'   U$ )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	   )clsvaluess     T/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/chains/natbot/base.pyraise_deprecationNatBotChain.raise_deprecationC   sT     F?MM  	 &(VE]-F&,ve}&<?P&P{#    c                    Sn[        U5      e)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   kwargsmsgs       r-   from_defaultNatBotChain.from_defaultQ   s    @ 	
 "#&&r0   c                >    [         U-  [        5       -  nU " SXBS.UD6$ )zLoad from LLM.)r   r    )r   r	   )r+   r   r   r3   r   s        r-   from_llmNatBotChain.from_llm[   s(     SL?#44	FYFvFFr0   c                2    U R                   U R                  /$ )z0Expect url and browser content.

:meta private:
)r   r   selfs    r-   
input_keysNatBotChain.input_keysf   s     ""D$B$BCCr0   c                    U R                   /$ )z Return command.

:meta private:
)r    r<   s    r-   output_keysNatBotChain.output_keysn   s       r0   c                P   U=(       d    [         R                  " 5       nXR                     nXR                     nU R                  R                  U R                  US S U R                  US S S.SUR                  5       0S9nUR                  5       nX`l        U R                  U0$ )Nd   i  )r   r   r   r   	callbacks)config)r   get_noop_managerr   r   r   invoker   r   	get_childstripr    )r=   inputsrun_manager_run_managerr   r   llm_cmds          r-   _callNatBotChain._callv   s    
 #S&@&Q&Q&S''( !?!?@..''!^^4Cy$($9$9#25D#9	  !7!7!9: ( 
 --/ '))r0   c                `    U R                   UU R                  U0nU " U5      U R                     $ )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    )r=   r   r   _inputss       r-   executeNatBotChain.execute   s6    " **O
 G}T__--r0   c                    g)Nnat_bot_chainr8   r<   s    r-   _chain_typeNatBotChain._chain_type   s    r0   )r   )r,   dictreturnr   )r   r   r3   r   rZ   r   )r   r   r   r   r3   r   rZ   r   )rZ   z	list[str])N)rK   dict[str, str]rL   z$Optional[CallbackManagerForChainRun]rZ   r[   )r   r   r   r   rZ   r   )rZ   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   r   r   r   r    r   model_configr   classmethodr.   r5   r9   propertyr>   rA   rO   rS   rW   __static_attributes__r8   r0   r-   r   r      s>   , N:'+C	$+*M3%6s6cJ $L
 (#
  $
 ' ' GG G 	G
 
G G D D ! ! =A** :* 
	**.,  r0   r   )r`   
__future__r   r)   typingr   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   r8   r0   r-   <module>rp      sY    & "    * ? < 9 - 0 ' 1 
	>
 	F% F	Fr0   