a
    dŠÝg»  ã                   @  s:   d dl mZ d dlmZmZ d dlmZ G dd„ dƒZdS )é    )Úannotations)ÚListÚOptional)ÚThoughtc                   @  s~   e Zd ZdZdddœdd„Zddœd	d
„Zddddœdd„Zddœdd„Zdddœdd„Ze	ddœdd„ƒZ
ddœdd„ZdS )ÚToTDFSMemoryzŸ
    Memory for the Tree of Thought (ToT) chain.

    It is implemented as a stack of
    thoughts. This allows for a depth first search (DFS) of the ToT.
    NzOptional[List[Thought]]©Ústackc                 C  s   |pg | _ d S )Nr   )Úselfr   © r
   úo/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_experimental/tot/memory.pyÚ__init__   s    zToTDFSMemory.__init__zOptional[Thought])Úreturnc                 C  s   t | jƒdkr| jd S dS )z,Get the top of the stack without popping it.r   éÿÿÿÿN©Úlenr   ©r	   r
   r
   r   Útop   s    zToTDFSMemory.topé   Úint)Únr   c                 C  s.   t | jƒ|k rdS t|ƒD ]}| j ¡ }q|S )z<Pop the top n elements of the stack and return the last one.N)r   r   ÚrangeÚpop)r	   r   Ú_Únoder
   r
   r   r      s
    zToTDFSMemory.popc                 C  s   t | jƒdkr| jd S dS )z:Get the parent of the top of the stack without popping it.r   éþÿÿÿNr   r   r
   r
   r   Ú
top_parent   s    zToTDFSMemory.top_parentr   ÚNone)r   r   c                 C  s0   t | jƒdkr | jd j |¡ | j |¡ dS )z#Add a node on the top of the stack.r   r   N)r   r   ÚchildrenÚaddÚappend)r	   r   r
   r
   r   Ústore#   s    zToTDFSMemory.storec                 C  s
   t | jƒS )z&Return the current level of the stack.r   r   r
   r
   r   Úlevel)   s    zToTDFSMemory.levelzList[Thought]c                 C  s   | j dd… S )zReturn the thoughts path.Nr   r   r
   r
   r   Úcurrent_path.   s    zToTDFSMemory.current_path)N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r    Úpropertyr!   r"   r
   r
   r
   r   r      s   r   N)Ú
__future__r   Útypingr   r   Z"langchain_experimental.tot.thoughtr   r   r
   r
   r
   r   Ú<module>   s   