HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langchain/memory/__pycache__/buffer.cpython-310.pyc
o

���gu�@s�ddlmZmZmZmZddlmZddlmZm	Z	ddl
mZddlm
Z
mZddlmZeddd	d
�Gdd�de
��Zeddd	d
�Gd
d�de��ZdS)�)�Any�Dict�List�Optional)�
deprecated)�BaseMessage�get_buffer_string)�pre_init)�BaseChatMemory�
BaseMemory)�get_prompt_input_keyz0.3.1z1.0.0z_Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/)�since�removal�messagec@seZdZUdZdZeed<dZeed<dZeed<e	de
fd	d
��Zde
fdd�Zd
e
edefdd�Ze	defdd��Zdefdd�Ze	de
efdd��Zde
efdd�Ze	de
efdd��Zdeee
fdeee
ffdd�Zdeee
fdeee
ffdd�ZdS) �ConversationBufferMemoryaSA basic memory implementation that simply stores the conversation history.

    This stores the entire conversation history in memory without any
    additional processing.

    Note that additional processing may be required in some situations when the
    conversation history is too large to fit in the context window of the model.
    �Human�human_prefix�AI�	ai_prefix�history�
memory_key�returncCs|jr|jS|jS)�String buffer of memory.)�return_messages�buffer_as_messages�
buffer_as_str��self�r�B/usr/local/lib/python3.10/dist-packages/langchain/memory/buffer.py�buffer!szConversationBufferMemory.bufferc�s$�|jr|��IdHS|��IdHS)rN)r�abuffer_as_messages�abuffer_as_strrrrr�abuffer&s����z ConversationBufferMemory.abuffer�messagescCst||j|jd�S)N)rr)rrr�rr$rrr�_buffer_as_str.s
�z'ConversationBufferMemory._buffer_as_strcCs|�|jj�S)�?Exposes the buffer as a string in case return_messages is True.)r&�chat_memoryr$rrrrr5sz&ConversationBufferMemory.buffer_as_strc�s�|j��IdH}|�|�S)r'N)r(�
aget_messagesr&r%rrrr":s�
z'ConversationBufferMemory.abuffer_as_strcCs|jjS)�JExposes the buffer as a list of messages in case return_messages is False.)r(r$rrrrr?sz+ConversationBufferMemory.buffer_as_messagesc�s�|j��IdHS)r*N)r(r)rrrrr!Ds�z,ConversationBufferMemory.abuffer_as_messagescC�|jgS)zMWill always return list of memory variables.

        :meta private:
        �rrrrr�memory_variablesHsz)ConversationBufferMemory.memory_variables�inputscC�|j|jiS�zReturn history buffer.�rr �rr.rrr�load_memory_variablesP�z.ConversationBufferMemory.load_memory_variablesc�s�|��IdH}|j|iS)z9Return key-value pairs given the text input to the chain.N)r#r)rr.r rrr�aload_memory_variablesTs�
z/ConversationBufferMemory.aload_memory_variablesN)�__name__�
__module__�__qualname__�__doc__r�str�__annotations__rr�propertyrr r#rrr&rr"rr!r-rr3r5rrrrrs&
		"&rc@s4eZdZUdZdZeed<dZeed<	dZeed<dZ	e
eed	<dZe
eed
<dZeed<e
d
edefdd��Zedeefdd��Zdeeefdeeeffdd�Zdeeefdeeeffdd�Zdeeefdeeefddfdd�Zdeeefdeeefddfdd�Zd!dd�Zd!dd �ZdS)"�ConversationStringBufferMemorya�A basic memory implementation that simply stores the conversation history.

    This stores the entire conversation history in memory without any
    additional processing.

    Equivalent to ConversationBufferMemory but tailored more specifically
    for string-based conversations rather than chat models.

    Note that additional processing may be required in some situations when the
    conversation history is too large to fit in the context window of the model.
    rrrr�r N�
output_key�	input_keyrr�valuesrcCs|�dd�r
td��|S)z*Validate that return messages is not True.rFz@return_messages must be False for ConversationStringBufferMemory)�get�
ValueError)�clsrArrr�validate_chainsws
�z.ConversationStringBufferMemory.validate_chainscCr+)zLWill always return list of memory variables.
        :meta private:
        r,rrrrr-�sz/ConversationStringBufferMemory.memory_variablesr.cCr/r0r1r2rrrr3�r4z4ConversationStringBufferMemory.load_memory_variablesc�s�|�|�Sr0)r3r2rrrr5�s�
z5ConversationStringBufferMemory.aload_memory_variables�outputscCs�|jdurt||j�}n|j}|jdur,t|�dkr#td|������t|���d}n|j}|j�d�||}|j	�d�||}|j
dd�||g�7_
dS)�.Save context from this conversation to buffer.N�zOne output key expected, got rz: �
)r@rr-r?�lenrC�keys�listrrr �join)rr.rF�prompt_input_keyr?�human�airrr�save_context�s

 z+ConversationStringBufferMemory.save_contextc�s�|�||�S)rG)rQ)rr.rFrrr�
asave_context�s�z,ConversationStringBufferMemory.asave_contextcCs
d|_dS)zClear memory contents.r>N)r rrrr�clear�s
z$ConversationStringBufferMemory.clearc�s�|��dS)N)rSrrrr�aclear�s�z%ConversationStringBufferMemory.aclear)rN)r6r7r8r9rr:r;rr r?rr@rr	rrEr<rr-rr3r5rQrRrSrTrrrrr=Zs2
	""&
�
�
�
r=N)�typingrrrr�langchain_core._apir�langchain_core.messagesrr�langchain_core.utilsr	�langchain.memory.chat_memoryr
r�langchain.memory.utilsrrr=rrrr�<module>s$�G�