o
    ȳgE$                     @   s   d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
Z
ddlZddlmZmZ ddlmZ G dd deZG d	d
 d
eZG dd deZG dd deZeZdS )z@Lightweight wrapper around requests library, with async support.    )asynccontextmanager)AnyAsyncGeneratorDictLiteralOptionalUnionN)	BaseModel
ConfigDict)Responsec                   @   s  e Zd ZU dZdZeeeef  ed< dZ	ee
j ed< dZee ed< dZee ed< eddd	Zd
ededejfddZd
edeeef dedejfddZd
edeeef dedejfddZd
edeeef dedejfddZd
ededejfddZeded
ededee
jdf fddZed
ededee
jdf fddZed
edeeef dedee
jdf fddZed
edeeef dedee
jdf fdd Zed
edeeef dedee
jdf fd!d"Z ed
ededee
jdf fd#d$Z!dS )%RequestszWrapper around requests to handle auth and async.

    The main purpose of this wrapper is to handle authentication (by saving
    headers) and enable easy async methods on the same base object.
    Nheaders
aiosessionauthTverifyforbidarbitrary_types_allowedextraurlkwargsreturnc                 K       t j|f| j| j| jd|S ) GET the URL and return the text.r   r   r   )requestsgetr   r   r   selfr   r    r   b/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/requests.pyr         zRequests.getdatac                 K   "   t j|f|| j| j| jd|S )$POST to the URL and return the text.jsonr   r   r   )r   postr   r   r   r   r   r"   r   r   r   r    r'   #      zRequests.postc                 K   r#   )"PATCH the URL and return the text.r%   )r   patchr   r   r   r(   r   r   r    r+   .   r)   zRequests.patchc                 K   r#   ) PUT the URL and return the text.r%   )r   putr   r   r   r(   r   r   r    r-   9   r)   zRequests.putc                 K   r   )#DELETE the URL and return the text.r   )r   deleter   r   r   r   r   r   r    r/   D   r!   zRequests.deletemethodc              
   K  s  | j sQt 4 I dH 8}|j||f| j| jd|4 I dH }|V  W d  I dH  n1 I dH s4w   Y  W d  I dH  dS 1 I dH sJw   Y  dS | j j||f| j| jd|4 I dH }|V  W d  I dH  dS 1 I dH szw   Y  dS )zMake an async request.N)r   r   )r   aiohttpClientSessionrequestr   r   )r   r0   r   r   sessionresponser   r   r    	_arequestJ   s8   *.
.zRequests._arequestc              	   K  V   | j d|fi |4 I dH }|V  W d  I dH  dS 1 I dH s$w   Y  dS )/GET the URL and return the text asynchronously.GETNr6   r   r   r   r5   r   r   r    agetc      .zRequests.agetc              	   K  Z   | j d|fd|i|4 I dH }|V  W d  I dH  dS 1 I dH s&w   Y  dS )3POST to the URL and return the text asynchronously.POSTr&   Nr:   r   r   r"   r   r5   r   r   r    apostk      ".zRequests.apostc              	   K  r>   )1PATCH the URL and return the text asynchronously.PATCHr&   Nr:   rA   r   r   r    apatchs   rC   zRequests.apatchc              	   K  r>   )/PUT the URL and return the text asynchronously.PUTr&   Nr:   rA   r   r   r    aput{   rC   zRequests.aputc              	   K  r7   )2DELETE the URL and return the text asynchronously.DELETENr:   r;   r   r   r    adelete   r=   zRequests.adelete)"__name__
__module____qualname____doc__r   r   r   str__annotations__r   r1   r2   r   r   r   boolr
   model_configr   r   r   r'   r+   r-   r/   r   r   ClientResponser6   r<   rB   rF   rI   rL   r   r   r   r    r      s   
 $$$


r   c                   @   s  e Zd ZU dZdZeeeef  ed< dZ	ee
j ed< dZee ed< dZed ed< d	Zeed
< ed	ddZedefddZdedeeeeef f fddZde
jdeeeeef f fddZdededeeeeef f fddZdedeeef dedeeeeef f fddZdedeeef dedeeeeef f fddZdedeeef dedeeeeef f fddZdededeeeeef f fd d!Z dededeeeeef f fd"d#Z!dedeeef dedeeeeef f fd$d%Z"dedeeef dedeeeeef f fd&d'Z#dedeeef dedeeeeef f fd(d)Z$dededeeeeef f fd*d+Z%dS ),GenericRequestsWrapperz,Lightweight wrapper around requests library.Nr   r   r   textrW   r&   response_content_typeTr   r   r   r   c                 C   s   t | j| j| j| jdS )N)r   r   r   r   )r   r   r   r   r   )r   r   r   r    r      s   zGenericRequestsWrapper.requestsr5   c                 C   s2   | j dkr|jS | j dkr| S td| j  NrW   r&   zInvalid return type: rY   rW   r&   
ValueErrorr   r5   r   r   r    _get_resp_content   s
   

z(GenericRequestsWrapper._get_resp_contentc                    sB   | j dkr| I d H S | j dkr| I d H S td| j  rZ   r[   r]   r   r   r    _aget_resp_content   s   

z)GenericRequestsWrapper._aget_resp_contentr   r   c                 K      |  | jj|fi |S )r   )r^   r   r   r   r   r   r    r         zGenericRequestsWrapper.getr"   c                 K      |  | jj||fi |S )r$   )r^   r   r'   r(   r   r   r    r'         zGenericRequestsWrapper.postc                 K   rb   )r*   )r^   r   r+   r(   r   r   r    r+      rc   zGenericRequestsWrapper.patchc                 K   rb   )r,   )r^   r   r-   r(   r   r   r    r-      rc   zGenericRequestsWrapper.putc                 K   r`   )r.   )r^   r   r/   r   r   r   r    r/      ra   zGenericRequestsWrapper.deletec              	      ^   | j j|fi |4 I dH }| |I dH W  d  I dH  S 1 I dH s(w   Y  dS )r8   N)r   r<   r_   r;   r   r   r    r<         0zGenericRequestsWrapper.agetc              	      `   | j j||fi |4 I dH }| |I dH W  d  I dH  S 1 I dH s)w   Y  dS )r?   N)r   rB   r_   rA   r   r   r    rB          0zGenericRequestsWrapper.apostc              	      rf   )rD   N)r   rF   r_   rA   r   r   r    rF      rg   zGenericRequestsWrapper.apatchc              	      rf   )rG   N)r   rI   r_   rA   r   r   r    rI      rg   zGenericRequestsWrapper.aputc              	      rd   )rJ   N)r   rL   r_   r;   r   r   r    rL      re   zGenericRequestsWrapper.adelete)&rM   rN   rO   rP   r   r   r   rQ   rR   r   r1   r2   r   r   rY   r   r   rS   r
   rT   propertyr   r   r   r   r^   rU   r_   r   r'   r+   r-   r/   r<   rB   rF   rI   rL   r   r   r   r    rV      s   
 "
&






&&





*rV   c                   @   "   e Zd ZU dZdZed ed< dS )JsonRequestsWrapperzLightweight wrapper around requests library, with async support.

    The main purpose of this wrapper is to always return a json output.r&   rX   rY   NrM   rN   rO   rP   rY   r   rR   r   r   r   r    rj         
 rj   c                   @   ri   )TextRequestsWrapperzLightweight wrapper around requests library, with async support.

    The main purpose of this wrapper is to always return a text output.rW   rX   rY   Nrk   r   r   r   r    rm      rl   rm   )rP   
contextlibr   typingr   r   r   r   r   r   r1   r   pydanticr	   r
   r   r   rV   rj   rm   RequestsWrapperr   r   r   r    <module>   s      c	