
    Ng                     @   d Z ddlZddlmZmZmZmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ ded	eeef         fd
Zded	efdZ G d de          Z G d dee          Z G d dee          Z G d dee          Z G d dee          Z G d dee          ZdS )z-Tools for making requests to an API endpoint.    N)AnyDictOptionalUnion)	BaseModel)AsyncCallbackManagerForToolRunCallbackManagerForToolRun)GenericRequestsWrapper)BaseTooltextreturnc                 *    t          j        |           S )z"Parse the json string into a dict.)jsonloads)r   s    c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/requests/tool.py_parse_inputr      s    :d    urlc                 ,    |                      d          S )zStrips quotes from the url.z"')strip)r   s    r   
_clean_urlr      s    99Ur   c                   B     e Zd ZU dZeed<   dZeed<   def fdZ	 xZ
S )BaseRequestsToolzBase class for requests tools.requests_wrapperFallow_dangerous_requestskwargsc                     |                     dd          st          d           t                      j        di | dS )zInitialize the tool.r   Fa  You must set allow_dangerous_requests to True to use this tool. Requests can be dangerous and can lead to security vulnerabilities. For example, users can ask a server to make a request to an internal server. It's recommended to use requests through a proxy server and avoid accepting inputs from untrusted sources without proper sandboxing.Please see: https://python.langchain.com/docs/security for further security information.N )get
ValueErrorsuper__init__)selfr   	__class__s     r   r"   zBaseRequestsTool.__init__"   sV    zz4e<< 
	0	 	 	 	""6"""""r   )__name__
__module____qualname____doc__r
   __annotations__r   boolr   r"   __classcell__)r$   s   @r   r   r      si         ((,,,,%*d***# # # # # # # # # # #r   r   c                       e Zd ZU dZdZeed<   dZeed<   	 ddedee	         d	e
eeeef         f         fd
Z	 ddedee         d	e
eeeef         f         fdZdS )RequestsGetToolz1Tool for making a GET request to an API endpoint.requests_getnamezA portal to the internet. Use this when you need to get specific
    content from a website. Input should be a  url (i.e. https://www.google.com).
    The output will be the text response of the GET request.
    descriptionNr   run_managerr   c                 P    | j                             t          |                    S Run the tool.)r   r   r   r#   r   r1   s      r   _runzRequestsGetTool._run;   s!     $((C999r   c                 `   K   | j                             t          |                     d{V S Run the tool asynchronously.N)r   agetr   r5   s      r   _arunzRequestsGetTool._arunA   s7       *//
3@@@@@@@@@r   Nr%   r&   r'   r(   r/   strr)   r0   r   r	   r   r   r   r6   r   r;   r   r   r   r-   r-   2   s         ;;D#K    LP: ::%-.G%H:	sDcN"	#: : : : AEA AA <=A 
sDcN"	#	A A A A A Ar   r-   c                       e Zd ZU dZdZeed<   dZeed<   	 ddedee	         d	e
eeeef         f         fd
Z	 ddedee         d	e
eeeef         f         fdZdS )RequestsPostToolz2Tool for making a POST request to an API endpoint.requests_postr/   a  Use this when you want to POST to a website.
    Input should be a json string with two keys: "url" and "data".
    The value of "url" should be a string, and the value of "data" should be a dictionary of 
    key-value pairs you want to POST to the url.
    Be careful to always use double quotes for strings in the json string
    The output will be the text response of the POST request.
    r0   Nr   r1   r   c                     	 t          |          }| j                            t          |d                   |d                   S # t          $ r}t          |          cY d}~S d}~ww xY wr4   r   dataN)r   r   postr   	Exceptionreprr#   r   r1   rD   es        r   r6   zRequestsPostTool._runV   sq    	%%D(--je.E.EtF|TTT 	 	 	77NNNNNN	   AA 
A(A#A(#A(c                    K   	 t          |          }| j                            t          |d                   |d                    d{V S # t          $ r}t          |          cY d}~S d}~ww xY wr9   r   rD   N)r   r   apostr   rF   rG   rH   s        r   r;   zRequestsPostTool._arun`   s      	%%D.444;''f          	 	 	77NNNNNN	   AA 
A0A+%A0+A0r<   r=   r   r   r   r@   r@   J   s         <<D#K    MQ &./H&I	sDcN"	#    AE  <= 
sDcN"	#	     r   r@   c                       e Zd ZU dZdZeed<   dZeed<   	 ddedee	         d	e
eeeef         f         fd
Z	 ddedee         d	e
eeeef         f         fdZdS )RequestsPatchToolz3Tool for making a PATCH request to an API endpoint.requests_patchr/   a  Use this when you want to PATCH to a website.
    Input should be a json string with two keys: "url" and "data".
    The value of "url" should be a string, and the value of "data" should be a dictionary of 
    key-value pairs you want to PATCH to the url.
    Be careful to always use double quotes for strings in the json string
    The output will be the text response of the PATCH request.
    r0   Nr   r1   r   c                     	 t          |          }| j                            t          |d                   |d                   S # t          $ r}t          |          cY d}~S d}~ww xY wrC   )r   r   patchr   rF   rG   rH   s        r   r6   zRequestsPatchTool._run{   sq    	%%D(..z$u+/F/FVUUU 	 	 	77NNNNNN	rJ   c                    K   	 t          |          }| j                            t          |d                   |d                    d{V S # t          $ r}t          |          cY d}~S d}~ww xY wrL   )r   r   apatchr   rF   rG   rH   s        r   r;   zRequestsPatchTool._arun   s      	%%D.554;''f          	 	 	77NNNNNN	rN   r<   r=   r   r   r   rP   rP   o   s         == D#   K    MQ &./H&I	sDcN"	#    AE  <= 
sDcN"	#	     r   rP   c                       e Zd ZU dZdZeed<   dZeed<   	 ddedee	         d	e
eeeef         f         fd
Z	 ddedee         d	e
eeeef         f         fdZdS )RequestsPutToolz1Tool for making a PUT request to an API endpoint.requests_putr/   a  Use this when you want to PUT to a website.
    Input should be a json string with two keys: "url" and "data".
    The value of "url" should be a string, and the value of "data" should be a dictionary of 
    key-value pairs you want to PUT to the url.
    Be careful to always use double quotes for strings in the json string.
    The output will be the text response of the PUT request.
    r0   Nr   r1   r   c                     	 t          |          }| j                            t          |d                   |d                   S # t          $ r}t          |          cY d}~S d}~ww xY wrC   )r   r   putr   rF   rG   rH   s        r   r6   zRequestsPutTool._run   sq    	%%D(,,ZU-D-Dd6lSSS 	 	 	77NNNNNN	rJ   c                    K   	 t          |          }| j                            t          |d                   |d                    d{V S # t          $ r}t          |          cY d}~S d}~ww xY wrL   )r   r   aputr   rF   rG   rH   s        r   r;   zRequestsPutTool._arun   s      	%%D.334;''f          	 	 	77NNNNNN	rN   r<   r=   r   r   r   rW   rW      s         ;;D#K    MQ &./H&I	sDcN"	#    AE  <= 
sDcN"	#	     r   rW   c                       e Zd ZU dZdZeed<   dZeed<   	 ddedee	         d	e
eeeef         f         fd
Z	 ddedee         d	e
eeeef         f         fdZdS )RequestsDeleteToolz4Tool for making a DELETE request to an API endpoint.requests_deleter/   zA portal to the internet.
    Use this when you need to make a DELETE request to a URL.
    Input should be a specific url, and the output will be the text
    response of the DELETE request.
    r0   Nr   r1   r   c                 P    | j                             t          |                    S r3   )r   deleter   r5   s      r   r6   zRequestsDeleteTool._run   s!     $++JsOO<<<r   c                 `   K   | j                             t          |                     d{V S r8   )r   adeleter   r5   s      r   r;   zRequestsDeleteTool._arun   s7       *22:c??CCCCCCCCCr   r<   r=   r   r   r   r^   r^      s         >>!D#!!!K    <@= == 78= 
sDcN"	#	= = = = AED DD <=D 
sDcN"	#	D D D D D Dr   r^   )r(   r   typingr   r   r   r   pydanticr   langchain_core.callbacksr   r	   &langchain_community.utilities.requestsr
   langchain_core.toolsr   r>   r   r   r   r-   r@   rP   rW   r^   r   r   r   <module>ri      s   3 3  - - - - - - - - - - - -             
 J I I I I I ) ) ) ) ) )s tCH~    
C C    
# # # # #y # # #.A A A A A& A A A0" " " " "' " " "J" " " " "(( " " "J" " " " "& " " "JD D D D D)8 D D D D Dr   