
    Ngh                        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e          Z G d	 d
e          ZddZ G d de          Z G d de          ZdS )    )annotationsN)OptionalType)AsyncCallbackManagerForToolRunCallbackManagerForToolRun)BaseTool)	BaseModelc                  6    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        \/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/plugin.pyr   r      s<         IIIHHH.3333333r   r   c                      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            ZdS )AIPluginzAI Plugin Definition.r   schema_versionname_for_modelname_for_humandescription_for_modeldescription_for_humanNzOptional[dict]authr   apiOptional[str]logo_urlcontact_emaillegal_info_urlr   returnc                ^    t          j        |                                          } | di |S )z Instantiate AIPlugin from a URL.r   )requestsgetjson)clsr   responses      r   from_urlzAIPlugin.from_url&   s1     <$$))++sXr   )r   r   r%   r   )r   r   r   r   r   r   classmethodr,   r   r   r   r   r      s         DNNN    !!!!   [  r   r   txtr   r%   dictc                ~    	 t          j        |           S # t           j        $ r t          j        |           cY S w xY 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yaml	safe_load)r.   s    r   marshal_specr5   -   sI    #z# # # #~c"""""#s    #<<c                  "    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   r9   r   r   r   r   r7   r7   <   s)         "" "J""""""r   r7   c                  j    e Zd ZU dZded<   ded<   eZded<   edd
            Z	 	 dddZ		 	 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                   t                               |          }d|j         d|j         d|j        z   }t	          j        |j        j                  j        }t          |          }d|j
         d| } | |j        |||          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<   r=   )r   r,   r   r   r'   r(   r    r   textr5   r   r   )r*   r   r<   rA   open_api_spec_stropen_api_specr=   s          r   from_plugin_urlzAIPluginTool.from_plugin_urlI   s    ""3''8(.(=8 8 $8 8 8 () %L88=$%677-F8 - -*- - 	
 s&#	
 
 
 	
r   r8   Nr9   r!   run_manager#Optional[CallbackManagerForToolRun]c                    | j         S )zUse the tool.r=   selfr9   rF   s      r   _runzAIPluginTool._run`   s     }r   (Optional[AsyncCallbackManagerForToolRun]c                   K   | j         S )zUse the tool asynchronously.rI   rJ   s      r   _arunzAIPluginTool._arunh   s       }r   )r   r   r%   r;   )r8   N)r9   r!   rF   rG   r%   r   )NN)r9   r!   rF   rM   r%   r   )r   r   r   r   r   r7   r>   r-   rE   rL   rO   r   r   r   r;   r;   B   s         ==MMM,>K>>>>
 
 
 [
0 %';?     %)@D      r   r;   )r.   r   r%   r/   )
__future__r   r)   typingr   r   r'   r3   langchain_core.callbacksr   r   langchain_core.toolsr   pydanticr	   r   r   r5   r7   r;   r   r   r   <module>rU      s^   " " " " " "  ! ! ! ! ! ! ! !          * ) ) ) ) )      4 4 4 4 4	 4 4 4    y   *# # # ## # # # # # # #, , , , ,8 , , , , ,r   