
    7|h                        d Z ddlm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mZmZ ddlmZ d	d
iZ G d de      Zy)z<Chain that hits a URL and then uses an LLM to parse results.    )annotations)AnyDictListOptional)LLMChain)Chain)CallbackManagerForChainRun)
ConfigDictFieldmodel_validator)TextRequestsWrapperz
User-AgentzrMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36c                      e Zd ZU dZde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d       Zedd       Z ed      edd              Z	 d	 	 	 	 	 d dZed!d       Zy)"LLMRequestsChainab  Chain that requests a URL and then uses an LLM to parse results.

    **Security Note**: This chain can make GET requests to arbitrary URLs,
        including internal URLs.

        Control access to who can run this chain and what network access
        this chain has.

        See https://python.langchain.com/docs/security for more information.
    r   	llm_chainc                 "    t        t              S )N)headers)r   DEFAULT_HEADERS     f/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/chains/llm_requests.py<lambda>zLLMRequestsChain.<lambda>!   s     3O L r   T)default_factoryexcluder   requests_wrapperi@  inttext_lengthrequests_resultstrrequests_keyurl	input_keyoutput
output_keyforbid)arbitrary_types_allowedextrac                    | j                   gS )zJWill be whatever keys the prompt expects.

        :meta private:
        )r"   selfs    r   
input_keyszLLMRequestsChain.input_keys.   s     r   c                    | j                   gS )z=Will always return text key.

        :meta private:
        )r$   r)   s    r   output_keyszLLMRequestsChain.output_keys6   s       r   before)modec                D    	 ddl m} |S # t        $ r t        d      w xY w)z?Validate that api key and python package exists in environment.r   BeautifulSoupzNCould not import bs4 python package. Please install it with `pip install bs4`.)bs4r2   ImportError)clsvaluesr2   s      r   validate_environmentz%LLMRequestsChain.validate_environment>   s4    	)   	< 	s   
 Nc                   ddl m} |xs t        j                         }|j	                         D ci c]  \  }}|| j
                  k7  s|| }}}|| j
                     }| j                  j                  |      }	 ||	d      }
|
j                         d | j                   || j                  <    | j                  j                  dd|j                         i|}| j                  |iS c c}}w )Nr   r1   zhtml.parser	callbacksr   )r3   r2   r
   get_noop_manageritemsr"   r   getget_textr   r    r   predict	get_childr$   )r*   inputsrun_managerr2   _run_managerkv
other_keysr!   ressoupresults               r   _callzLLMRequestsChain._callL   s    
 	&"S&@&Q&Q&S'-||~Mtq!dnn9LadM
MT^^$##'',S-0(,8J$:J:J(K
4$$%''' 
",,.
2<
 (( Ns   C)
C)c                     y)Nllm_requests_chainr   r)   s    r   _chain_typezLLMRequestsChain._chain_type`   s    #r   )returnz	List[str])r6   r   rM   r   )N)r@   Dict[str, Any]rA   z$Optional[CallbackManagerForChainRun]rM   rN   )rM   r   )__name__
__module____qualname____doc____annotations__r   r   r   r    r"   r$   r   model_configpropertyr+   r-   r   classmethodr7   rI   rL   r   r   r   r   r      s    	 ,1L-)  K)L#)IsJ $L
     ! ! (#
  $
 =A)) :) 
	)( $ $r   r   N)rR   
__future__r   typingr   r   r   r   langchain.chainsr   langchain.chains.baser	   langchain_core.callbacksr
   pydanticr   r   r   &langchain_community.utilities.requestsr   r   r   r   r   r   <module>r^      sC    B " , , % ' ? 7 7 F   G
O$u O$r   