o
    Zhh                     @  s   d dl mZ d dlZd dlmZmZ d dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZ G dd deZG d	d
 d
eZdddZG dd deZG dd deZdS )    )annotationsN)OptionalType)AsyncCallbackManagerForToolRunCallbackManagerForToolRun)BaseTool)	BaseModelc                   @  s.   e Zd ZU dZded< ded< dZded< dS )		ApiConfigzAPI Configuration.strtypeurlFzOptional[bool]has_user_authenticationN)__name__
__module____qualname____doc____annotations__r    r   r   W/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/tools/plugin.pyr	      s
   
 r	   c                   @  st   e Zd ZU dZded< ded< ded< ded< ded< dZd	ed
< ded< ded< ded< ded< edddZdS )AIPluginzAI Plugin Definition.r
   Zschema_versionname_for_modelname_for_humandescription_for_modeldescription_for_humanNzOptional[dict]authr	   apiOptional[str]Zlogo_urlZcontact_emailZlegal_info_urlr   returnc                 C  s   t | }| di |S )z Instantiate AIPlugin from a URL.Nr   )requestsgetjson)clsr   responser   r   r   from_url&   s   zAIPlugin.from_url)r   r
   r   r   )r   r   r   r   r   r   classmethodr#   r   r   r   r   r      s   
 r   txtr
   r   dictc                 C  s,   zt | W S  t jy   t|  Y S w )zConvert the yaml or json serialized spec to a dict.

    Args:
        txt: The yaml or json serialized spec.

    Returns:
        dict: The spec as a dict.
    )r    loadsJSONDecodeErroryamlZ	safe_load)r%   r   r   r   marshal_spec-   s
   	r*   c                   @  s   e Zd ZU dZdZded< dS )AIPluginToolSchemazSchema for AIPluginTool. r   
tool_inputN)r   r   r   r   r-   r   r   r   r   r   r+   <   s   
 r+   c                   @  s\   e Zd ZU dZded< ded< eZded< edd
dZ		ddddZ			ddddZ
dS )AIPluginToolz3Tool for getting the OpenAPI spec for an AI Plugin.r   pluginr
   api_speczType[AIPluginToolSchema]args_schemar   r   c                 C  sb   t |}d|j d|j d|j }t|jjj}t	|}d|j
 d| }| |j|||dS )NzRCall this tool to get the OpenAPI spec (and usage guide) for interacting with the z2 API. You should only call this ONCE! What is the z API useful for? zUsage Guide: z

OpenAPI Spec: )namedescriptionr/   r0   )r   r#   r   r   r   r   r   r   textr*   r   r   )r!   r   r/   r3   Zopen_api_spec_strZopen_api_specr0   r   r   r   from_plugin_urlI   s(   

zAIPluginTool.from_plugin_urlr,   Nr-   r   run_manager#Optional[CallbackManagerForToolRun]c                 C  s   | j S )zUse the tool.r0   selfr-   r6   r   r   r   _run`   s   zAIPluginTool._run(Optional[AsyncCallbackManagerForToolRun]c                   s   | j S )zUse the tool asynchronously.r8   r9   r   r   r   _arunh   s   zAIPluginTool._arun)r   r
   r   r.   )r,   N)r-   r   r6   r7   r   r
   )NN)r-   r   r6   r<   r   r
   )r   r   r   r   r   r+   r1   r$   r5   r;   r=   r   r   r   r   r.   B   s   
 
r.   )r%   r
   r   r&   )
__future__r   r    typingr   r   r   r)   Zlangchain_core.callbacksr   r   Zlangchain_core.toolsr   Zpydanticr   r	   r   r*   r+   r.   r   r   r   r   <module>   s    
