
    Fd"                         d Z ddlmZmZmZmZmZmZmZ ddl	m
Z
  ed          Z G d de          Z G d de
          Zd	S )
zHandles loading of plugins.    )AnyDictListOptionalTuple	TypedDictTypeVar)AutoGPTPluginTemplatePromptGeneratorc                   $    e Zd ZU eed<   eed<   dS )MessagerolecontentN)__name__
__module____qualname__str__annotations__     VC:\Users\Administrator\Downloads\Auto-GPT-master\autogpt\models\base_open_ai_plugin.pyr   r   	   s"         
IIILLLLLr   r   c            
       N   e Zd ZdZdefdZdefdZdedefdZ	defdZ
d	edefd
ZdefdZd	edee         dee         fdZdefdZdedefdZdefdZdee         dee         fdZdefdZdee         dee         fdZdefdZdedefdZdefdZdedeeef         deeeeef         f         fdZdefdZdededefdZ deeef         dede!de"def
dZ#dee         dede!de"def
d Z$d!edefd"Z%d!ede&fd#Z'd$edefd%Z(d$edefd&Z)defd'Z*d(edd)fd*Z+d)S )+BaseOpenAIPluginzK
    This is a BaseOpenAIPlugin class for generating Auto-GPT plugins.
    manifests_specs_clientsc                     |d         d         | _         |d         d         | _        |d         d         | _        |d         | _        |d         | _        |d         | _        d S )Nmanifestname_for_modelschema_versiondescription_for_modelclientopenapi_spec)_name_version_description_client	_manifest_openapi_spec)selfr   s     r   __init__zBaseOpenAIPlugin.__init__   sd    ,Z89IJ
/
;<LM3J?@WX.x80<4^Dr   returnc                     dS )zThis method is called to check that the plugin can
        handle the on_response method.
        Returns:
            bool: True if the plugin can handle the on_response method.Fr   r(   s    r   can_handle_on_responsez'BaseOpenAIPlugin.can_handle_on_response   	    
 ur   responsec                     |S )zAThis method is called when a response is received from the model.r   )r(   r/   argskwargss       r   on_responsezBaseOpenAIPlugin.on_response#   s    r   c                     dS )zThis method is called to check that the plugin can
        handle the post_prompt method.
        Returns:
            bool: True if the plugin can handle the post_prompt method.Fr   r,   s    r   can_handle_post_promptz'BaseOpenAIPlugin.can_handle_post_prompt'   r.   r   promptc                     |S )a  This method is called just after the generate_prompt is called,
            but actually before the prompt is generated.
        Args:
            prompt (PromptGenerator): The prompt generator.
        Returns:
            PromptGenerator: The prompt generator.
        r   )r(   r6   s     r   post_promptzBaseOpenAIPlugin.post_prompt.   s	     r   c                     dS )zThis method is called to check that the plugin can
        handle the on_planning method.
        Returns:
            bool: True if the plugin can handle the on_planning method.Fr   r,   s    r   can_handle_on_planningz'BaseOpenAIPlugin.can_handle_on_planning8   r.   r   messagesc                     dS )zThis method is called before the planning chat completion is done.
        Args:
            prompt (PromptGenerator): The prompt generator.
            messages (List[str]): The list of messages.
        Nr   )r(   r6   r;   s      r   on_planningzBaseOpenAIPlugin.on_planning?         r   c                     dS )zThis method is called to check that the plugin can
        handle the post_planning method.
        Returns:
            bool: True if the plugin can handle the post_planning method.Fr   r,   s    r   can_handle_post_planningz)BaseOpenAIPlugin.can_handle_post_planningH   r.   r   c                     |S )zThis method is called after the planning chat completion is done.
        Args:
            response (str): The response.
        Returns:
            str: The resulting response.
        r   r(   r/   s     r   post_planningzBaseOpenAIPlugin.post_planningO   	     r   c                     dS )zThis method is called to check that the plugin can
        handle the pre_instruction method.
        Returns:
            bool: True if the plugin can handle the pre_instruction method.Fr   r,   s    r   can_handle_pre_instructionz+BaseOpenAIPlugin.can_handle_pre_instructionX   r.   r   c                     |S )zThis method is called before the instruction chat is done.
        Args:
            messages (List[Message]): The list of context messages.
        Returns:
            List[Message]: The resulting list of messages.
        r   r(   r;   s     r   pre_instructionz BaseOpenAIPlugin.pre_instruction_   rD   r   c                     dS )zThis method is called to check that the plugin can
        handle the on_instruction method.
        Returns:
            bool: True if the plugin can handle the on_instruction method.Fr   r,   s    r   can_handle_on_instructionz*BaseOpenAIPlugin.can_handle_on_instructionh   r.   r   c                     dS )zThis method is called when the instruction chat is done.
        Args:
            messages (List[Message]): The list of context messages.
        Returns:
            Optional[str]: The resulting message.
        Nr   rH   s     r   on_instructionzBaseOpenAIPlugin.on_instructiono   r>   r   c                     dS )zThis method is called to check that the plugin can
        handle the post_instruction method.
        Returns:
            bool: True if the plugin can handle the post_instruction method.Fr   r,   s    r   can_handle_post_instructionz,BaseOpenAIPlugin.can_handle_post_instructionw   r.   r   c                     |S )zThis method is called after the instruction chat is done.
        Args:
            response (str): The response.
        Returns:
            str: The resulting response.
        r   rB   s     r   post_instructionz!BaseOpenAIPlugin.post_instruction~   rD   r   c                     dS )zThis method is called to check that the plugin can
        handle the pre_command method.
        Returns:
            bool: True if the plugin can handle the pre_command method.Fr   r,   s    r   can_handle_pre_commandz'BaseOpenAIPlugin.can_handle_pre_command   r.   r   command_name	argumentsc                 
    ||fS )a  This method is called before the command is executed.
        Args:
            command_name (str): The command name.
            arguments (Dict[str, Any]): The arguments.
        Returns:
            Tuple[str, Dict[str, Any]]: The command name and the arguments.
        r   )r(   rT   rU   s      r   pre_commandzBaseOpenAIPlugin.pre_command   s     Y&&r   c                     dS )zThis method is called to check that the plugin can
        handle the post_command method.
        Returns:
            bool: True if the plugin can handle the post_command method.Fr   r,   s    r   can_handle_post_commandz(BaseOpenAIPlugin.can_handle_post_command   r.   r   c                     |S )zThis method is called after the command is executed.
        Args:
            command_name (str): The command name.
            response (str): The response.
        Returns:
            str: The resulting response.
        r   )r(   rT   r/   s      r   post_commandzBaseOpenAIPlugin.post_command   s	     r   modeltemperature
max_tokensc                     dS )a  This method is called to check that the plugin can
          handle the chat_completion method.
        Args:
            messages (List[Message]): The messages.
            model (str): The model name.
            temperature (float): The temperature.
            max_tokens (int): The max tokens.
          Returns:
              bool: True if the plugin can handle the chat_completion method.Fr   r(   r;   r\   r]   r^   s        r   can_handle_chat_completionz+BaseOpenAIPlugin.can_handle_chat_completion   s	     ur   c                     dS )aE  This method is called when the chat completion is done.
        Args:
            messages (List[Message]): The messages.
            model (str): The model name.
            temperature (float): The temperature.
            max_tokens (int): The max tokens.
        Returns:
            str: The resulting response.
        Nr   r`   s        r   handle_chat_completionz'BaseOpenAIPlugin.handle_chat_completion   r>   r   textc                     dS )a	  This method is called to check that the plugin can
          handle the text_embedding method.
        Args:
            text (str): The text to be convert to embedding.
          Returns:
              bool: True if the plugin can handle the text_embedding method.Fr   r(   rd   s     r   can_handle_text_embeddingz*BaseOpenAIPlugin.can_handle_text_embedding   s	     ur   c                     dS )zThis method is called when the chat completion is done.
        Args:
            text (str): The text to be convert to embedding.
        Returns:
            list: The text embedding.
        Nr   rf   s     r   handle_text_embeddingz&BaseOpenAIPlugin.handle_text_embedding   r>   r   
user_inputc                     dS )zThis method is called to check that the plugin can
        handle the user_input method.

        Args:
            user_input (str): The user input.

        Returns:
            bool: True if the plugin can handle the user_input method.Fr   r(   rj   s     r   can_handle_user_inputz&BaseOpenAIPlugin.can_handle_user_input   s	     ur   c                     dS )zThis method is called to request user input to the user.

        Args:
            user_input (str): The question or prompt to ask the user.

        Returns:
            str: The user input.
        Nr   rl   s     r   rj   zBaseOpenAIPlugin.user_input   r>   r   c                     dS )zThis method is called to check that the plugin can
        handle the report method.

        Returns:
            bool: True if the plugin can handle the report method.Fr   r,   s    r   can_handle_reportz"BaseOpenAIPlugin.can_handle_report   s	     ur   messageNc                     dS )zThis method is called to report a message to the user.

        Args:
            message (str): The message to report.
        Nr   )r(   rq   s     r   reportzBaseOpenAIPlugin.report   r>   r   ),r   r   r   __doc__dictr)   boolr-   r   r3   r5   r   r8   r:   r   r   r   r=   r@   rC   rF   rI   rK   rM   rO   rQ   rS   r   r   r   rW   rY   r[   floatintra   rc   rg   listri   rm   rj   rp   rs   r   r   r   r   r      s        E E E E E    C S        / o        %15g	#   $    c c    D    W $w-    4    tG} #    T             
'
',0cN
'	sDcN"	#
' 
' 
' 
'          S#X/2AFTW	   W.1@ESV	   c d    # $    	 	 	 	 	 	S S    4    c d      r   r   N)rt   typingr   r   r   r   r   r   r	   auto_gpt_plugin_templater
   r   r   r   r   r   r   <module>r|      s    ! ! G G G G G G G G G G G G G G G G G G : : : : : :'+,,    i   
k k k k k, k k k k kr   