o
    ȳg                     @  s   d dl mZ d dlmZmZ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 d d	lmZ d d
lmZ G dd deZdS )    )annotations)AnyListOptionalSequence)BaseLanguageModel)BaseTool)BaseToolkit)Field)NLATool)OpenAPISpec)AIPlugin)Requestsc                   @  s   e Zd ZU dZedZded< 	 d%ddZe			
d&d'ddZ	e
			
d&d(ddZe
			
d&d)ddZe
			
d&d*d d!Ze
			
d&d+d#d$Zd	S ),
NLAToolkita  Natural Language API Toolkit.

    *Security Note*: This toolkit creates tools that enable making calls
        to an Open API compliant API.

        The tools created by this toolkit may be able to make GET, POST,
        PATCH, PUT, DELETE requests to any of the exposed endpoints on
        the API.

        Control access to who can use this toolkit.

        See https://python.langchain.com/docs/security for more information.
    .zSequence[NLATool]	nla_toolsreturnList[BaseTool]c                 C  s
   t | jS ))Get the tools for all the API operations.)listr   )self r   j/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/agent_toolkits/nla/toolkit.py	get_tools"   s   
zNLAToolkit.get_toolsNFllmr   specr   requestsOptional[Requests]verboseboolkwargsr   List[NLATool]c           	      K  sV   |j sg S g }|j D ]}||D ]}tjd| |||||d|}|| qq
|S )r   )r   pathmethodr   r   r   Nr   )pathsget_methods_for_pathr   from_llm_and_methodappend)	r   r   r   r   r   http_operation_toolsr!   r"   endpoint_toolr   r   r   _get_http_operation_tools&   s$   	
	z$NLAToolkit._get_http_operation_toolsc                 K  s$   | j d||||d|}| |dS )a  Instantiate the toolkit by creating tools for each operation.

        Args:
            llm: The language model to use.
            spec: The OpenAPI spec.
            requests: Optional requests object. Default is None.
            verbose: Whether to print verbose output. Default is False.
            kwargs: Additional arguments.

        Returns:
            The toolkit.
        r   r   r   r   )r   Nr   )r)   )clsr   r   r   r   r   r'   r   r   r   from_llm_and_spec@   s   
zNLAToolkit.from_llm_and_specopen_api_urlstrc                 K  $   t |}| jd||||d|S )a  Instantiate the toolkit from an OpenAPI Spec URL.

        Args:
            llm: The language model to use.
            open_api_url: The URL of the OpenAPI spec.
            requests: Optional requests object. Default is None.
            verbose: Whether to print verbose output. Default is False.
            kwargs: Additional arguments.

        Returns:
            The toolkit.
        r*   Nr   )r   from_urlr,   )r+   r   r-   r   r   r   r   r   r   r   from_llm_and_urlZ   s   
zNLAToolkit.from_llm_and_url	ai_pluginr   c                 K  s(   t |jj}| jd||||d|S )0Instantiate the toolkit from an OpenAPI Spec URLr*   Nr   )r   r0   apiurlr,   )r+   r   r2   r   r   r   r   r   r   r   from_llm_and_ai_pluginu   s   
z!NLAToolkit.from_llm_and_ai_pluginai_plugin_urlc                 K  r/   )r3   )r   r2   r   r   Nr   )r   r0   r6   )r+   r   r7   r   r   r   pluginr   r   r   from_llm_and_ai_plugin_url   s   

z%NLAToolkit.from_llm_and_ai_plugin_url)r   r   )NF)r   r   r   r   r   r   r   r   r   r   r   r    )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r-   r.   r   r   r   r   r   r   r   r   )r   r   r2   r   r   r   r   r   r   r   r   r   )r   r   r7   r.   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r
   r   __annotations__r   staticmethodr)   classmethodr,   r1   r6   r9   r   r   r   r   r      s2   
 
r   N)
__future__r   typingr   r   r   r   langchain_core.language_modelsr   langchain_core.toolsr   langchain_core.tools.baser	   pydanticr
   +langchain_community.agent_toolkits.nla.toolr   5langchain_community.tools.openapi.utils.openapi_utilsr    langchain_community.tools.pluginr   &langchain_community.utilities.requestsr   r   r   r   r   r   <module>   s    