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__/summary.cpython-310.pyc
o

���gb�@sddlmZddlmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZddlmZddlmZmZmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z edddd�Gdd�de��Z!edddd�Gdd�dee!��Z"e"�#�dS)�)�annotations)�Any�Dict�List�Type)�
deprecated)�	BaseCache)�	Callbacks)�BaseChatMessageHistory)�BaseLanguageModel)�BaseMessage�
SystemMessage�get_buffer_string)�BasePromptTemplate)�pre_init)�	BaseModel)�LLMChain)�BaseChatMemory)�SUMMARY_PROMPTz0.2.12z1.0z�Refer here for how to incorporate summaries of conversation history: https://langchain-ai.github.io/langgraph/how-tos/memory/add-summary-conversation-history/)�since�removal�messagec@s^eZdZUdZdZded<dZded<ded<eZd	ed
<e	Z
ded<ddd�Zddd�ZdS)�SummarizerMixinzMixin for summarizer.�Human�str�human_prefix�AI�	ai_prefixr�llmr�promptzType[BaseMessage]�summary_message_cls�messages�List[BaseMessage]�existing_summary�returncCs0t||j|jd�}t|j|jd�}|j||d�S�N)rr)rr)�summary�	new_lines)rrrrrr�predict��selfr!r#r'�chain�r,�C/usr/local/lib/python3.10/dist-packages/langchain/memory/summary.py�predict_new_summary%s�z#SummarizerMixin.predict_new_summaryc�s8�t||j|jd�}t|j|jd�}|j||d�IdHSr%)rrrrrr�apredictr)r,r,r-�apredict_new_summary1s��z$SummarizerMixin.apredict_new_summaryN)r!r"r#rr$r)
�__name__�
__module__�__qualname__�__doc__r�__annotations__rrrr
r r.r0r,r,r,r-rs
	
rz0.3.1z1.0.0z_Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/cs�eZdZUdZdZded<dZded<edd�d&dd��Ze	d'dd��Z
d(dd�Zed)dd��Z
d*�fd"d#�Zd+�fd$d%�Z�ZS),�ConversationSummaryMemoryz�Continually summarizes the conversation history.

    The summary is updated after each conversation turn.
    The implementations returns a summary of the conversation history which
    can be used to provide context to the model.
    �r�buffer�history�
memory_key�)�summarize_steprr�chat_memoryr
r<�int�kwargsrr$cKsR|d||d�|��}tdt|jj�|�D]}|�|jj|||�|j�|_q|S)N)rr=rr,)�range�lenr=r!r.r8)�clsrr=r<r?�obj�ir,r,r-�
from_messagesQs	�z'ConversationSummaryMemory.from_messages�	List[str]cCs|jgS)zMWill always return list of memory variables.

        :meta private:
        )r:�r*r,r,r-�memory_variablesasz*ConversationSummaryMemory.memory_variables�inputs�Dict[str, Any]cCs(|jr|j|jd�g}n|j}|j|iS)zReturn history buffer.)�content)�return_messagesr r8r:)r*rIr8r,r,r-�load_memory_variablesis
z/ConversationSummaryMemory.load_memory_variables�valuesrcCs8|dj}ddh}|t|�krtd|�d|�d���|S)z4Validate that prompt input variables are consistent.rr&r'z:Got unexpected prompt input variables. The prompt expects z, but it should have �.)�input_variables�set�
ValueError)rBrN�prompt_variables�
expected_keysr,r,r-�validate_prompt_input_variablesqs
���z9ConversationSummaryMemory.validate_prompt_input_variables�outputs�Dict[str, str]�Nonecs.t��||�|�|jjdd�|j�|_dS)z.Save context from this conversation to buffer.���N)�super�save_contextr.r=r!r8)r*rIrV��	__class__r,r-r[}s
�z&ConversationSummaryMemory.save_contextcst���d|_dS)zClear memory contents.r7N)rZ�clearr8rGr\r,r-r^�s

zConversationSummaryMemory.clear)
rrr=r
r<r>r?rr$r6)r$rF)rIrJr$rJ)rNrr$r)rIrJrVrWr$rX)r$rX)r1r2r3r4r8r5r:�classmethodrE�propertyrHrMrrUr[r^�
__classcell__r,r,r\r-r6>s
	�
r6N)$�
__future__r�typingrrrr�langchain_core._apir�langchain_core.cachesr�langchain_core.callbacksr	�langchain_core.chat_historyr
�langchain_core.language_modelsr�langchain_core.messagesrr
r�langchain_core.promptsr�langchain_core.utilsr�pydanticr�langchain.chains.llmr�langchain.memory.chat_memoryr�langchain.memory.promptrrr6�
model_rebuildr,r,r,r-�<module>s6�"�D