a
    bg                     @  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dZed!dddddddddZ	e
d"dddddd dddZe
d#dddddd dddZe
d$dddddd dddZe
d%ddddd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_toolszList[BaseTool])returnc                 C  s
   t | jS ))Get the tools for all the API operations.)listr   )self r   |/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/agent_toolkits/nla/toolkit.py	get_tools"   s    zNLAToolkit.get_toolsNFr   r   zOptional[Requests]boolr   zList[NLATool])llmspecrequestsverbosekwargsr   c           	      K  sV   |j s
g S g }|j D ]<}||D ],}tjf | |||||d|}|| q"q|S )r   )r   pathmethodr   r   r   )pathsZget_methods_for_pathr   Zfrom_llm_and_methodappend)	r   r   r   r   r   http_operation_toolsr   r   Zendpoint_toolr   r   r   _get_http_operation_tools&   s"    	
	z$NLAToolkit._get_http_operation_toolsc                 K  s$   | j f ||||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   )r#   )clsr   r   r   r   r   r"   r   r   r   from_llm_and_spec@   s    zNLAToolkit.from_llm_and_specstr)r   open_api_urlr   r   r   r   c                 K  s$   t |}| jf ||||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$   )r   from_urlr&   )r%   r   r(   r   r   r   r   r   r   r   from_llm_and_urlZ   s    
zNLAToolkit.from_llm_and_urlr   )r   	ai_pluginr   r   r   r   c                 K  s(   t |jj}| jf ||||d|S )0Instantiate the toolkit from an OpenAPI Spec URLr$   )r   r)   apiurlr&   )r%   r   r+   r   r   r   r   r   r   r   from_llm_and_ai_pluginu   s    
z!NLAToolkit.from_llm_and_ai_plugin)r   ai_plugin_urlr   r   r   r   c                 K  s$   t |}| jf ||||d|S )r,   )r   r+   r   r   )r   r)   r/   )r%   r   r0   r   r   r   pluginr   r   r   from_llm_and_ai_plugin_url   s    

z%NLAToolkit.from_llm_and_ai_plugin_url)NF)NF)NF)NF)NF)__name__
__module____qualname____doc__r
   r   __annotations__r   staticmethodr#   classmethodr&   r*   r/   r2   r   r   r   r   r      s.   
          r   N)
__future__r   typingr   r   r   r   Zlangchain_core.language_modelsr   Zlangchain_core.toolsr   Zlangchain_core.tools.baser	   Zpydanticr
   Z+langchain_community.agent_toolkits.nla.toolr   Z5langchain_community.tools.openapi.utils.openapi_utilsr   Z langchain_community.tools.pluginr   Z&langchain_community.utilities.requestsr   r   r   r   r   r   <module>   s   