
    Ng                        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dS )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dS )+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     c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/chains/llm_requests.py<lambda>zLLMRequestsChain.<lambda>!   s     3O L L 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extrareturn	List[str]c                    | 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)modevaluesr   r   c                P    	 ddl m} n# t          $ r t          d          w xY w|S )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`.)bs4r6   ImportError)clsr3   r6   s      r   validate_environmentz%LLMRequestsChain.validate_environment>   sU    	))))))) 	 	 	<  	
 s   	 #NinputsDict[str, Any]run_manager$Optional[CallbackManagerForChainRun]c                    ddl m} |pt          j                    } fd|                                D             }| j                 } j                            |          } ||d          }|                                d  j	                 | j
        <     j        j        dd|                                i|}	 j        |	iS )Nr   r5   c                2    i | ]\  }}|j         k    ||S r   r+   ).0kvr-   s      r   
<dictcomp>z*LLMRequestsChain._call.<locals>.<dictcomp>U   s+    MMMtq!dn9L9La9L9L9Lr   zhtml.parser	callbacksr   )r7   r6   r
   get_noop_manageritemsr"   r   getget_textr   r    r   predict	get_childr$   )
r-   r;   r=   r6   _run_manager
other_keysr!   ressoupresults
   `         r   _callzLLMRequestsChain._callL   s    
 	&%%%%%"S&@&Q&S&SMMMMv||~~MMM
T^$#'',,}S-00(,8J$:J8J(K
4$%'' 
 
",,..
2<
 
 ((r   c                    dS )Nllm_requests_chainr   r,   s    r   _chain_typezLLMRequestsChain._chain_type`   s    ##r   )r(   r)   )r3   r   r(   r   )N)r;   r<   r=   r>   r(   r<   )r(   r   )__name__
__module____qualname____doc____annotations__r   r   r   r    r"   r$   r   model_configpropertyr.   r0   r   classmethodr:   rQ   rT   r   r   r   r   r      s{        	 	 ,1ELL- - -     K)L))))IJ: $  L
       X  ! ! ! X! _(###
 
 
 [ $#
 =A) ) ) ) )( $ $ $ X$ $ $r   r   N)rX   
__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>rd      s    B B " " " " " " , , , , , , , , , , , , % % % % % % ' ' ' ' ' ' ? ? ? ? ? ? 7 7 7 7 7 7 7 7 7 7 F F F F F F   G
O$ O$ O$ O$ O$u O$ O$ O$ O$ O$r   