a
    bg                     @  s   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 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                   @  s   e Zd ZU dZded< edd 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ddZeddddZeddeddd d!d"Zd+d$d%d$d&d'd(Zedd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                   C  s
   t tdS )N)headers)r   DEFAULT_HEADERS r   r   u/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/chains/llm_requests.py<lambda>!       zLLMRequestsChain.<lambda>T)default_factoryexcluder   requests_wrapperi@  inttext_lengthZrequests_resultstrrequests_keyurl	input_keyoutput
output_keyZforbid)Zarbitrary_types_allowedextraz	List[str])returnc                 C  s   | j gS )zJWill be whatever keys the prompt expects.

        :meta private:
        r   selfr   r   r   
input_keys.   s    zLLMRequestsChain.input_keysc                 C  s   | j gS )z=Will always return text key.

        :meta private:
        )r    r$   r   r   r   output_keys6   s    zLLMRequestsChain.output_keysbefore)moder   r   )valuesr"   c                 C  s0   zddl m} W n ty*   tdY n0 |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`.)bs4r,   ImportError)clsr*   r,   r   r   r   validate_environment>   s    
z%LLMRequestsChain.validate_environmentNzDict[str, Any]z$Optional[CallbackManagerForChainRun])inputsrun_managerr"   c           
        s   ddl m} |pt } fdd| D }| j } j|}||d}| d  j	 | j
<  jjf d| i|}	 j|	iS )Nr   r+   c                   s    i | ]\}}| j kr||qS r   r#   ).0kvr$   r   r   
<dictcomp>U   r   z*LLMRequestsChain._call.<locals>.<dictcomp>zhtml.parser	callbacks)r-   r,   r	   Zget_noop_manageritemsr   r   getZget_textr   r   r   ZpredictZ	get_childr    )
r%   r1   r2   r,   Z_run_managerZ
other_keysr   resZsoupresultr   r$   r   _callL   s    


zLLMRequestsChain._callc                 C  s   dS )NZllm_requests_chainr   r$   r   r   r   _chain_type`   s    zLLMRequestsChain._chain_type)N)__name__
__module____qualname____doc____annotations__r   r   r   r   r   r    r
   Zmodel_configpropertyr&   r'   r   classmethodr0   r<   r=   r   r   r   r   r      s2   
 r   N)rA   
__future__r   typingr   r   r   r   Zlangchain.chainsr   Zlangchain.chains.baser   Zlangchain_core.callbacksr	   Zpydanticr
   r   r   Z&langchain_community.utilities.requestsr   r   r   r   r   r   r   <module>   s   