a
    dgz                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 eddd	ZG d
d deZedddZG dd deZeddged e dZdS )    N)dedent)List)BaseOutputParser)PromptTemplate)ThoughtValidityreturnc                   C   s   t dddgtd dS )z4Get the prompt for the Chain of Thought (CoT) chain.jinja2problem_descriptionthoughtsa  
            You are an intelligent agent that is generating one thought at a time in
            a tree of thoughts setting.

            PROBLEM 
            
            {{problem_description}}
            
            {% if thoughts %}
            THOUGHTS
            
            {% for thought in thoughts %}
            {{ thought }}
            {% endfor %}
            {% endif %}
            
            Let's think step by step.
            )template_formatinput_variablestemplate)r   r   strip r   r   p/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_experimental/tot/prompts.pyget_cot_prompt   s    r   c                   @   s6   e Zd ZdZeedddZeee dddZdS )	JSONListOutputParserz.Parse the output of a PROPOSE_PROMPT response.r   c                 C   s   dS )NZ	json_listr   selfr   r   r   _type+   s    zJSONListOutputParser._typetextr   c                 C   sF   | dd  d }zt|W S  tjy@   g  Y S 0 dS )z Parse the output of an LLM call.z```json   z```N)splitr   jsonloadsJSONDecodeError)r   r   Zjson_stringr   r   r   parse/   s
    zJSONListOutputParser.parseN)	__name__
__module____qualname____doc__propertystrr   r   r   r   r   r   r   r   (   s   r   c                   C   s   t dg dt td dS )z,Get the prompt for the PROPOSE_PROMPT chain.r	   )r
   r   na-  
                You are an intelligent agent that is generating thoughts in a tree of
                thoughts setting.
                
                The output should be a markdown code snippet formatted as a JSON list of
                strings, including the leading and trailing "```json" and "```":
                
                ```json
                [
                "<thought-1>",
                "<thought-2>",
                "<thought-3>"
                ]
                ```
                
                PROBLEM
                
                {{ problem_description }}
                
                {% if thoughts %}
                VALID THOUGHTS
                
                {% for thought in thoughts %}
                {{ thought }}
                {% endfor %}
                
                Possible next {{ n }} valid thoughts based on the last valid thought:
                {% else %}
                
                Possible next {{ n }} valid thoughts based on the PROBLEM:
                {%- endif -%}
                )r   r   output_parserr   )r   r   r   r   r   r   r   r   get_propose_prompt9   s    r'   c                   @   s2   e Zd ZdZeedddZeedddZdS )	CheckerOutputParserz1Parse and check the output of the language model.r   c                 C   s<   |  }d|v rtjS d|v r$tjS d|v r2tjS tjS dS )z'Parse the output of the language model.INVALIDZINTERMEDIATEZVALIDN)upperr   r)   ZVALID_INTERMEDIATEZVALID_FINAL)r   r   r   r   r   r   h   s    zCheckerOutputParser.parser   c                 C   s   dS )NZtot_llm_checker_outputr   r   r   r   r   r   t   s    zCheckerOutputParser._typeN)	r   r    r!   r"   r$   r   r   r#   r   r   r   r   r   r(   e   s   r(   r
   r   a$  
        You are an intelligent agent, validating thoughts of another intelligent agent.

        PROBLEM 
        
        {problem_description}

        THOUGHTS
        
        {thoughts}

        Evaluate the thoughts and respond with one word.

        - Respond VALID if the last thought is a valid final solution to the
        problem.
        - Respond INVALID if the last thought is invalid.
        - Respond INTERMEDIATE if the last thought is valid but not the final
        solution to the problem.

        This chain of thoughts is)r   r   r&   )r   textwrapr   typingr   Zlangchain_core.output_parsersr   Zlangchain_core.promptsr   Z"langchain_experimental.tot.thoughtr   r   r   r'   r(   r   ZCHECKER_PROMPTr   r   r   r   <module>   s    ,