a
    bg
                     @  s|   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 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                   @  sJ   e Zd ZdZeddddddZedd
ddddddddd	ddZdS )NLAToolzNatural Language API Tool.r   strz	'NLATool')chain	api_titlereturnc                 C  s>   | dd d|jj }d| d|jj }| ||j|d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_operationZoperation_idr   run)clsr   r   Zexpanded_namer    r   y/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/agent_toolkits/nla/tool.pyfrom_open_api_endpoint_chain   s    z$NLATool.from_open_api_endpoint_chainNFr   r	   zOptional[Requests]boolr   )	llmpathmethodspecrequestsverbosereturn_intermediate_stepskwargsr   c                 K  s:   t |||}	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   Zfrom_openapi_specr   Zfrom_api_operationr   infotitle)r   r   r   r    r!   r"   r#   r$   r%   r   r   r   r   r   from_llm_and_method*   s    zNLATool.from_llm_and_method)NFF)__name__
__module____qualname____doc__classmethodr   r(   r   r   r   r   r      s      r   N)r,   
__future__r   typingr   r   Zlangchain_core.language_modelsr   Zlangchain_core.toolsr   Z(langchain_community.chains.openapi.chainr   Z2langchain_community.tools.openapi.utils.api_modelsr   Z5langchain_community.tools.openapi.utils.openapi_utilsr	   Z&langchain_community.utilities.requestsr
   r   r   r   r   r   <module>   s   