a
    ag                     @   sX   d dl 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 G dd deZdS )    N)AnyDictListSet)
BaseMemory)field_validator)BaseChatMemoryc                   @   s   e Zd ZU dZee ed< edeee ee dddZ	edeee ee dddZ
eee dd	d
Zeeef eeef dddZeeef eeef ddddZddddZdS )CombinedMemoryz+Combining multiple memories' data together.memories)valuereturnc                 C   sB   t  }|D ]2}||j}|r.td| d|t |jO }q
|S )NzThe same variables zL are found in multiplememory object, which is not allowed by CombinedMemory.)setintersectionmemory_variables
ValueError)clsr   Zall_variablesvaloverlap r   g/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain/memory/combined.pycheck_repeated_memory_variable   s    
z-CombinedMemory.check_repeated_memory_variablec                 C   s2   |D ](}t |tr|jdu rtd|  q|S )zHCheck that if memories are of type BaseChatMemory that input keys exist.NzWWhen using CombinedMemory, input keys should be so the input is known.  Was not set on )
isinstancer   Z	input_keywarningswarn)r   r   r   r   r   r   check_input_key!   s    

zCombinedMemory.check_input_key)r   c                 C   s    g }| j D ]}||j q
|S )z5All the memory variables that this instance provides.)r
   extendr   )selfr   memoryr   r   r   r   /   s    
zCombinedMemory.memory_variables)inputsr   c                 C   sP   i }| j D ]@}||}| D ](\}}||v r@td| d|||< q q
|S )z Load all vars from sub-memories.zThe variable z# is repeated in the CombinedMemory.)r
   load_memory_variablesitemsr   )r   r   Zmemory_datar   datakeyr   r   r   r   r   ;   s    


z$CombinedMemory.load_memory_variablesN)r   outputsr   c                 C   s   | j D ]}||| qdS )z0Save context from this session for every memory.N)r
   save_context)r   r   r#   r   r   r   r   r$   K   s    
zCombinedMemory.save_contextc                 C   s   | j D ]}|  qdS )z1Clear context from this session for every memory.N)r
   clear)r   r   r   r   r   r%   Q   s    
zCombinedMemory.clear)__name__
__module____qualname____doc__r   r   __annotations__r   classmethodr   r   propertystrr   r   r   r   r$   r%   r   r   r   r   r	   
   s   
 "r	   )r   typingr   r   r   r   Zlangchain_core.memoryr   Zpydanticr   Zlangchain.memory.chat_memoryr   r	   r   r   r   r   <module>   s
   