
    Ng                         d dl 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mZ d dlmZ d dlmZmZ d dlmZ d d	lmZ  e	d
dd           G d dee                      ZdS )    N)ABC)AnyDictOptionalTuple)
deprecated)BaseChatMessageHistoryInMemoryChatMessageHistory)
BaseMemory)	AIMessageHumanMessage)Field)get_prompt_input_keyz0.3.1z1.0.0z_Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/)sinceremovalmessagec                   4   e Zd ZU dZ ee          Zeed<   dZ	e
e         ed<   dZe
e         ed<   dZeed<   d	eeef         d
eeef         deeef         fdZd	eeef         d
eeef         ddfdZd	eeef         d
eeef         ddfdZddZddZdS )BaseChatMemoryax  Abstract base class for chat memory.

    **ATTENTION** This abstraction was created prior to when chat models had
        native tool calling capabilities.
        It does **NOT** support native tool calling capabilities for chat models and
        will fail SILENTLY if used with a chat model that has native tool calling.

    DO NOT USE THIS ABSTRACTION FOR NEW CODE.
    )default_factorychat_memoryN
output_key	input_keyFreturn_messagesinputsoutputsreturnc                    | j         t          || j                  }n| j         }| j        t	          |          dk    r(t          |                                          d         }njd|v r:d}t          j        d| j	        j
         d|                                 d           n,t          d|                                 d          | j        }||         ||         fS )	N   r   output'z' got multiple output keys: zc. The default 'output' key is being used. If this is not desired, please manually set 'output_key'.zGot multiple output keys: zT, cannot determine which to store in memory. Please set the 'output_key' explicitly.)r   r   memory_variablesr   lenlistkeyswarningswarn	__class____name__
ValueError)selfr   r   prompt_input_keyr   s        X/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/memory/chat_memory.py_get_input_outputz BaseChatMemory._get_input_output+   s    >!3FD<QRR#~?"7||q  !',,..11!4

W$$%
R/ R RR R R    !0 0 0 0   J&')<<<    c                     |                      ||          \  }}| j                            t          |          t	          |          g           dS z.Save context from this conversation to buffer.)contentN)r-   r   add_messagesr   r   r*   r   r   	input_str
output_strs        r,   save_contextzBaseChatMemory.save_contextF   s_     $ 6 6vw G G	:%%),,,i
.K.K.KL	
 	
 	
 	
 	
r.   c                    K   |                      ||          \  }}| j                            t          |          t	          |          g           d{V  dS r0   )r-   r   aadd_messagesr   r   r3   s        r,   asave_contextzBaseChatMemory.asave_contextM   s       !% 6 6vw G G	:,,),,,i
.K.K.KL
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r.   c                 8    | j                                          dS zClear memory contents.N)r   clearr*   s    r,   r<   zBaseChatMemory.clearV   s         r.   c                 H   K   | j                                          d{V  dS r;   )r   aclearr=   s    r,   r?   zBaseChatMemory.aclearZ   s3      %%'''''''''''r.   )r   N)r(   
__module____qualname____doc__r   r
   r   r	   __annotations__r   r   strr   r   boolr   r   r   r-   r6   r9   r<   r?    r.   r,   r   r      sh          +0%2+ + +K'    !%J$$$#Ix}###!OT!!!=38n=/3CH~=	sCx= = = =6
4S> 
DcN 
t 
 
 
 

38n
/3CH~
	
 
 
 
! ! ! !( ( ( ( ( (r.   r   )r%   abcr   typingr   r   r   r   langchain_core._apir   langchain_core.chat_historyr	   r
   langchain_core.memoryr   langchain_core.messagesr   r   pydanticr   langchain.memory.utilsr   r   rF   r.   r,   <module>rO      s:          - - - - - - - - - - - - * * * * * *        - , , , , , ; ; ; ; ; ; ; ;       7 7 7 7 7 7 
	G	  C( C( C( C( C(Z C( C( C( C( C(r.   