
    Fdc                         d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
 ddlmZ erddlmZ  G d d          Zd	e
d
efdZdS )z/ A module for generating custom prompt strings.    N)TYPE_CHECKINGAnyCallableDictListOptional)Config)llm_response_schema)CommandRegistryc            	           e Zd ZdZddZdeddfdZ	 	 ddeded	ee         ddfd
Z	de
eef         defdZdeddfdZdeddfdZddee         defdZdedefdZdS )PromptGeneratorz
    A class for generating custom prompt strings based on constraints, commands,
        resources, and performance evaluations.
    returnNc                 v    g | _         g | _        g | _        g | _        g | _        d| _        d| _        d| _        dS )z
        Initialize the PromptGenerator object with empty lists of constraints,
            commands, resources, and performance evaluations.
        NBobAI)constraintscommands	resourcesperformance_evaluationgoalscommand_registrynamerole)selfs    MC:\Users\Administrator\Downloads\Auto-GPT-master\autogpt\prompts\generator.py__init__zPromptGenerator.__init__   sC    
 &(#
8<				    
constraintc                 :    | j                             |           dS )z
        Add a constraint to the constraints list.

        Args:
            constraint (str): The constraint to be added.
        N)r   append)r   r   s     r   add_constraintzPromptGenerator.add_constraint    s!     	
+++++r   command_labelcommand_namefunctionc                     |i }d |                                 D             }||||d}| j                            |           dS )a  
        Add a command to the commands list with a label, name, and optional arguments.

        Args:
            command_label (str): The label of the command.
            command_name (str): The name of the command.
            args (dict, optional): A dictionary containing argument names and their
              values. Defaults to None.
            function (callable, optional): A callable function to be called when
                the command is executed. Defaults to None.
        Nc                     i | ]\  }}||	S  r'   ).0arg_key	arg_values      r   
<dictcomp>z/PromptGenerator.add_command.<locals>.<dictcomp>>   s    RRR/Aw	RRRr   )labelr   argsr$   )itemsr   r    )r   r"   r#   r-   r$   command_argscommands          r   add_commandzPromptGenerator.add_command)   sa    $ <DRRTZZ\\RRR #   	
 
 	W%%%%%r   r0   c                     d                     d |d                                         D                       }|d          d|d          d| S )z
        Generate a formatted string representation of a command.

        Args:
            command (dict): A dictionary containing command information.

        Returns:
            str: The formatted command string.
        z, c              3   .   K   | ]\  }}d | d| d V  dS )"z": "Nr'   )r(   keyvalues      r   	<genexpr>z;PromptGenerator._generate_command_string.<locals>.<genexpr>S   sK        
  
&0c5!!!!!! 
  
  
  
  
  
r   r-   r,   z: "r   z	", args: )joinr.   )r   r0   args_strings      r   _generate_command_stringz(PromptGenerator._generate_command_stringI   sj     ii  
  
4;FO4I4I4K4K 
  
  
 
 
 '"NNwvNNNNNr   resourcec                 :    | j                             |           dS )z|
        Add a resource to the resources list.

        Args:
            resource (str): The resource to be added.
        N)r   r    )r   r;   s     r   add_resourcezPromptGenerator.add_resourceX   s      	h'''''r   
evaluationc                 :    | j                             |           dS )z
        Add a performance evaluation item to the performance_evaluation list.

        Args:
            evaluation (str): The evaluation item to be added.
        N)r   r    )r   r>   s     r   add_performance_evaluationz*PromptGenerator.add_performance_evaluationa   s!     	#**:66666r   listr.   c                 J    |dk    rqg } j         r+|d  j         j                                        D             z  }| fd|D             z  }d                    d t	          |          D                       S d                    d t	          |          D                       S )aF  
        Generate a numbered list from given items based on the item_type.

        Args:
            items (list): A list of items to be numbered.
            item_type (str, optional): The type of items in the list.
                Defaults to 'list'.

        Returns:
            str: The formatted numbered list.
        r0   c                 :    g | ]}|j         	t          |          S r'   )enabledstr)r(   items     r   
<listcomp>z;PromptGenerator._generate_numbered_list.<locals>.<listcomp>y   s6     $ $ $|$II$ $ $r   c                 :    g | ]}                     |          S r'   )r:   )r(   rF   r   s     r   rG   z;PromptGenerator._generate_numbered_list.<locals>.<listcomp>   s'    VVV = =d C CVVVr   
c              3   0   K   | ]\  }}|d z    d| V  dS    z. Nr'   r(   irF   s      r   r7   z:PromptGenerator._generate_numbered_list.<locals>.<genexpr>   s8      XX'!T!--t--XXXXXXr   c              3   0   K   | ]\  }}|d z    d| V  dS rK   r'   rM   s      r   r7   z:PromptGenerator._generate_numbered_list.<locals>.<genexpr>   s8      NN'!T!--t--NNNNNNr   )r   r   valuesr8   	enumerate)r   r.   	item_typecommand_stringss   `   r   _generate_numbered_listz'PromptGenerator._generate_numbered_listj   s     	!! O$  $ $ $ 5 > E E G G$ $ $  VVVVPUVVVVO99XXY=W=WXXXXXX99NNYu=M=MNNNNNNr   configc                    d|                      | j                   dt          | |           d|                      | j                   d|                      | j                   dt          j        t          |                     dS )z
        Generate a prompt string based on the constraints, commands, resources,
            and performance evaluations.

        Returns:
            str: The generated prompt string.
        zConstraints:


zResources:
z

Performance Evaluation:
zD

Respond with only valid JSON conforming to the following schema: 
rI   )rT   r   generate_commandsr   r   jsondumpsr
   r   rU   s     r   generate_prompt_stringz&PromptGenerator.generate_prompt_string   s    ;T99$:JKK ; ; v..; ;77GG; ; ++D,GHH	; ; z-f5566; ; ;	
r   )r   N)NN)rA   )__name__
__module____qualname____doc__r   rE   r!   r   r   r1   r   r   r:   r=   r@   r   rT   r	   r\   r'   r   r   r   r      si        
   , , , , , , '+& && &
 8$& 
& & & &@OS#X O3 O O O O(S (T ( ( ( (7S 7T 7 7 7 7O OT#Y OS O O O O4
V 
 
 
 
 
 
 
r   r   rU   r   c                 T    |j         rdS d|                     | j        d           dS )z
    Generate a prompt string based on the constraints, commands, resources,
        and performance evaluations.

    Returns:
        str: The generated prompt string.
     z
Commands:
r0   )rR   rW   )openai_functionsrT   r   r[   s     r   rX   rX      sI      r	R'''KK	R 	R 	Rr   )r`   rY   typingr   r   r   r   r   r   autogpt.configr	   autogpt.json_utils.utilitiesr
   autogpt.models.command_registryr   r   rE   rX   r'   r   r   <module>rh      s    5 5  E E E E E E E E E E E E E E E E ! ! ! ! ! ! < < < < < < @??????H
 H
 H
 H
 H
 H
 H
 H
VF s      r   