o
    ȳg
                     @  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                   @  s4   e Zd ZdZeddd	Ze	
		ddddZd
S )NLAToolzNatural Language API Tool.chainr   	api_titlestrreturn	'NLATool'c                 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_operationoperation_idr   run)clsr   r   expanded_namer    r   g/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/agent_toolkits/nla/tool.pyfrom_open_api_endpoint_chain   s   z$NLATool.from_open_api_endpoint_chainNFllmr   pathmethodspecr	   requestsOptional[Requests]verbosebool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   from_openapi_specr   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)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   r.   r   r   r   r   r      s    r   N)r2   
__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   r   r   r   r   <module>   s    