a
    bgh                     @  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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   n/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/plugin.pyr	      s   
r	   c                   @  sz   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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_urlcontact_emailZlegal_info_urlr   returnc                 C  s   t | }| f i |S )z Instantiate AIPlugin from a URL.)requestsgetjson)clsr   responser   r   r   from_url&   s    zAIPlugin.from_url)r   r   r   r   r   r   classmethodr%   r   r   r   r   r      s   
r   r
   dict)txtr   c                 C  s0   zt | W S  t jy*   t|  Y S 0 dS )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.
    N)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                   @  sj   e Zd ZU dZded< ded< eZded< edd dd	d
ZdddddddZ	ddd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   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descriptionr1   r2   )r   r%   r   r   r    r!   r   r   textr,   r   r   )r#   r   r1   r5   Zopen_api_spec_strZopen_api_specr2   r   r   r   from_plugin_urlI   s(    

zAIPluginTool.from_plugin_urlr.   Nr   z#Optional[CallbackManagerForToolRun])r/   run_managerr   c                 C  s   | j S )zUse the tool.r2   selfr/   r8   r   r   r   _run`   s    zAIPluginTool._runz(Optional[AsyncCallbackManagerForToolRun]c                   s   | j S )zUse the tool asynchronously.r9   r:   r   r   r   _arunh   s    zAIPluginTool._arun)r.   N)NN)r   r   r   r   r   r-   r3   r&   r7   r<   r=   r   r   r   r   r0   B   s   
  
  r0   )
__future__r   r"   typingr   r   r    r+   Zlangchain_core.callbacksr   r   Zlangchain_core.toolsr   Zpydanticr   r	   r   r,   r-   r0   r   r   r   r   <module>   s   