
    Ng
                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ  G d
 de	          ZdS )zHTool for interacting with a single API with natural language definition.    )annotations)AnyOptional)BaseLanguageModel)Tool)OpenAPIEndpointChain)APIOperation)OpenAPISpec)Requestsc                  J    e Zd ZdZedd            Ze	 	 	 ddd            Zd	S )NLAToolzNatural Language API Tool.chainr   	api_titlestrreturn	'NLATool'c                    |                     dd           d|j        j         }d| d|j        j         } | ||j        |          S )zConvert an endpoint chain to an API endpoint tool.

        Args:
            chain: The endpoint chain.
            api_title: The title of the API.

        Returns:
            The API endpoint tool.
         _.zI'm an AI from zG. Instruct what you want, and I'll assist via an API with description: )namefuncdescription)replaceapi_operationoperation_idr   run)clsr   r   expanded_namer   s        g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/agent_toolkits/nla/tool.pyfrom_open_api_endpoint_chainz$NLATool.from_open_api_endpoint_chain   st       c**OOU-@-MOO 	2i 2 2#/2 2 	
 sEI;OOOO    NFllmr   pathmethodspecr
   requestsOptional[Requests]verboseboolreturn_intermediate_stepskwargsr   c                    t          j        |||          }	t          j        |	|f|||d|}
|                     |
|j        j                  S )a<  Instantiate the tool from the specified path and method.

        Args:
            llm: The language model to use.
            path: The path of the API.
            method: The method of the API.
            spec: The OpenAPI spec.
            requests: Optional requests object. Default is None.
            verbose: Whether to print verbose output. Default is False.
            return_intermediate_steps: Whether to return intermediate steps.
                Default is False.
            kwargs: Additional arguments.

        Returns:
            The tool.
        )r'   r)   r+   )r	   from_openapi_specr   from_api_operationr!   infotitle)r   r#   r$   r%   r&   r'   r)   r+   r,   r   r   s              r    from_llm_and_methodzNLATool.from_llm_and_method*   sk    8 %6tT6JJ$7
 &?
 
 
 
 //tyGGGr"   )r   r   r   r   r   r   )NFF)r#   r   r$   r   r%   r   r&   r
   r'   r(   r)   r*   r+   r*   r,   r   r   r   )__name__
__module____qualname____doc__classmethodr!   r2    r"   r    r   r      ss        $$P P P [P,  (,*/$H $H $H $H [$H $H $Hr"   r   N)r6   
__future__r   typingr   r   langchain_core.language_modelsr   langchain_core.toolsr   (langchain_community.chains.openapi.chainr   2langchain_community.tools.openapi.utils.api_modelsr	   5langchain_community.tools.openapi.utils.openapi_utilsr
   &langchain_community.utilities.requestsr   r   r8   r"   r    <module>rA      s    N N " " " " " "                 < < < < < < % % % % % % I I I I I I K K K K K K M M M M M M ; ; ; ; ; ;?H ?H ?H ?H ?Hd ?H ?H ?H ?H ?Hr"   