a
    •˜ëjÑ  ã                   @   s˜   d dl 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mZ d dlmZ d d	lmZ ed
ddd�G dd„ deeƒƒZdS )é    N)ÚABC)ÚAnyÚOptional)Ú
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/)ZsinceZremovalÚmessagec                   @   sÚ   e Zd ZU dZeed�Zeed< dZ	e
e ed< dZe
e ed< dZeed< eeef 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eeef eeef dd	œdd„Zddœdd„Zddœ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                 C   s¨   | j d u rt|| jƒ}n| j }| jd u r’t|ƒdkrFtt| ¡ ƒƒ}q˜d|v rxd}tj	d| j
j› d| ¡ › d�dd� q˜d| ¡ › d	�}t|ƒ‚n| j}|| || fS )
Né   Úoutputú'z' got multiple output keys: zc. The default 'output' key is being used. If this is not desired, please manually set 'output_key'.é   )Ú
stacklevelzGot multiple output keys: zT, cannot determine which to store in memory. Please set the 'output_key' explicitly.)r   r   Zmemory_variablesr   ÚlenÚnextÚiterÚkeysÚwarningsÚwarnÚ	__class__Ú__name__Ú
ValueError)Úselfr   r   Zprompt_input_keyr   Úmsg© r'   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/memory/chat_memory.pyÚ_get_input_output+   s&    

ÿüÿ
z BaseChatMemory._get_input_outputc                 C   s0   |   ||¡\}}| j t|d�t|d�g¡ dS ©z.Save context from this conversation to buffer.)ÚcontentN)r)   r   Zadd_messagesr
   r	   ©r%   r   r   Z	input_strZ
output_strr'   r'   r(   Úsave_contextJ   s    þÿzBaseChatMemory.save_contextc                 Ã   s6   |   ||¡\}}| j t|d�t|d�g¡I dH  dS r*   )r)   r   Zaadd_messagesr
   r	   r,   r'   r'   r(   Úasave_contextT   s    þÿzBaseChatMemory.asave_context)r   c                 C   s   | j  ¡  dS ©zClear memory contents.N)r   Úclear©r%   r'   r'   r(   r0   b   s    zBaseChatMemory.clearc                 Ã   s   | j  ¡ I dH  dS r/   )r   Úaclearr1   r'   r'   r(   r2   f   s    zBaseChatMemory.aclear)r#   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Ú__annotations__r   r   Ústrr   r   ÚboolÚdictr   Útupler)   r-   r.   r0   r2   r'   r'   r'   r(   r      s$   
	
ÿ


ü"

ür   )r    Úabcr   Útypingr   r   Zlangchain_core._apir   Zlangchain_core.chat_historyr   r   Zlangchain_core.memoryr   Zlangchain_core.messagesr	   r
   Zpydanticr   Zlangchain.memory.utilsr   r   r'   r'   r'   r(   Ú<module>   s   ü