a
    dg                     @   s   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ G dd	 d	e	ZG d
d deZG dd deZdS )a  
We provide two strategies for generating thoughts in the Tree of Thoughts (ToT)
framework to avoid repetition:

These strategies ensure that the language model generates diverse and
non-repeating thoughts, which are crucial for problem-solving tasks that require
exploration.
    )abstractmethod)AnyDictListTuple)LLMChain)BasePromptTemplate)Field)get_cot_promptget_propose_promptc                   @   s@   e Zd ZU dZdZeed< ed
ee	edf e
edddZd	S )BaseThoughtGenerationStrategyz7
    Base class for a thought generation strategy.
       c .problem_descriptionthoughts_pathkwargsreturnc                 K   s   dS )zt
        Generate the next thought given the problem description and the thoughts
        generated so far.
        Nr   )selfr   r   r   r   r   {/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_experimental/tot/thought_generation.pynext_thought   s    z*BaseThoughtGenerationStrategy.next_thoughtN)r   )__name__
__module____qualname____doc__r   int__annotations__r   strr   r   r   r   r   r   r   r      s   
 
r   c                   @   sB   e Zd ZU dZeedZeed< d
e	e
e	df ee	dddZd	S )SampleCoTStrategya  
    Sample strategy from a Chain-of-Thought (CoT) prompt.

    This strategy works better when the thought space is rich, such as when each
    thought is a paragraph. Independent and identically distributed samples
    lead to diversity, which helps to avoid repetition.
    default_factorypromptr   .r   c                 K   s(   | j f ||d|}t|tr$|S dS )N)r   thoughts )predict_and_parse
isinstancer   )r   r   r   r   Zresponse_textr   r   r   r   4   s    zSampleCoTStrategy.next_thoughtN)r   )r   r   r   r   r	   r
   r"   r   r   r   r   r   r   r   r   r   r   r   )   s   
 
r   c                   @   sh   e Zd ZU dZeedZeed< ee	dZ
eeedf ee f ed< deeedf eeddd	Zd
S )ProposePromptStrategya   
    Strategy that is sequentially using a "propose prompt".

    This strategy works better when the thought space is more constrained, such
    as when each thought is just a word or a line. Proposing different thoughts
    in the same prompt completion helps to avoid duplication.
    r    r"   .
tot_memoryr   r   c                 K   sh   || j vs| j | sZ| jf ||| jd|}|s6dS t|trV|d d d | j |< ndS | j |  S )N)r   r#   nr$   )r(   r%   r   r&   listpop)r   r   r   r   Znew_thoughtsr   r   r   r   L   s    
z"ProposePromptStrategy.next_thoughtN)r   )r   r   r   r   r	   r   r"   r   r   dictr(   r   r   r   r   r   r   r   r   r   r   r'   @   s   
& 
r'   N)r   abcr   typingr   r   r   r   Zlangchain.chains.llmr   Zlangchain_core.prompts.baser   Zpydanticr	   Z"langchain_experimental.tot.promptsr
   r   r   r   r'   r   r   r   r   <module>   s   	