
    Ah                         S SK JrJr  S SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  \" SSS	S
9 " S S\\5      5       rg)    )AnyUnion)
deprecated)BaseMessageget_buffer_string)pre_init)BaseChatMemory)SummarizerMixinz0.3.1z1.0.0z_Please see the migration guide at: https://python.langchain.com/docs/versions/migrating_memory/)sinceremovalmessagec                     ^  \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\	\S'   \S	\\	\\   4   4S
 j5       rS	\\	\\   4   4S jr\S	\\	   4S j5       rS\\	\4   S	\\	\4   4S jrS\\	\4   S	\\	\4   4S jr\S\S	\4S j5       rS\\	\4   S\\	\	4   S	S4U 4S jjrS\\	\4   S\\	\	4   S	S4U 4S jjrSS jrSS jrSU 4S jjrSU 4S jjrSrU =r$ )ConversationSummaryBufferMemory   a  Buffer with summarizer for storing conversation memory.

Provides a running summary of the conversation together with the most recent
messages in the conversation under the constraint that the total number of
tokens in the conversation does not exceed a certain limit.
i  max_token_limit moving_summary_bufferhistory
memory_keyreturnc                 >    U R                  0 5      U R                     $ )zString buffer of memory.)load_memory_variablesr   selfs    W/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/memory/summary_buffer.pybuffer&ConversationSummaryBufferMemory.buffer   s     ))"-doo>>    c                 \   #    U R                  0 5      I Sh  vN nXR                     $  N7f)zAsync memory buffer.N)aload_memory_variablesr   )r   memory_variabless     r   abuffer'ConversationSummaryBufferMemory.abuffer$   s,     !%!<!<R!@@00 As   ,*,c                     U R                   /$ )z=Will always return list of memory variables.

:meta private:
)r   r   s    r   r!   0ConversationSummaryBufferMemory.memory_variables)   s       r   inputsc                    U R                   R                  nU R                  S:w  a  U R                  U R                  S9/nX2-   nU R                  (       a  UnO[        UU R                  U R                  S9nU R                  U0$ )zReturn history buffer.r   contenthuman_prefix	ai_prefix)	chat_memorymessagesr   summary_message_clsreturn_messagesr   r+   r,   r   r   r&   r   first_messagesfinal_buffers        r   r   5ConversationSummaryBufferMemory.load_memory_variables1   s    !!**%%+((1K1K(L1N $,F &L,!....L
 ..r   c                 0  #    U R                   R                  5       I Sh  vN nU R                  S:w  a  U R                  U R                  S9/nX2-   nU R                  (       a  UnO[        UU R                  U R                  S9nU R                  U0$  Ns7f)zHAsynchronously return key-value pairs given the text input to the chain.Nr   r(   r*   )	r-   aget_messagesr   r/   r0   r   r+   r,   r   r1   s        r   r    6ConversationSummaryBufferMemory.aload_memory_variablesC   s     ''5577%%+((1K1K(L1N $,F &L,!....L
 .. 8s   BBA4Bvaluesc                 r    US   R                   nSS1nU[        U5      :w  a  SU SU S3n[        U5      eU$ )z4Validate that prompt input variables are consistent.promptsummary	new_linesz:Got unexpected prompt input variables. The prompt expects z, but it should have .)input_variablesset
ValueError)clsr8   prompt_variablesexpected_keysmsgs        r   validate_prompt_input_variables?ConversationSummaryBufferMemory.validate_prompt_input_variablesU   s[     "(+;;"K0C 011L#$$9-K  S/!r   outputsNc                 D   > [         TU ]  X5        U R                  5         g)z.Save context from this conversation to buffer.N)supersave_contextpruner   r&   rG   	__class__s      r   rJ   ,ConversationSummaryBufferMemory.save_contextb   s    V-

r   c                 t   >#    [         TU ]  X5      I Sh  vN   U R                  5       I Sh  vN   g N N7f)z=Asynchronously save context from this conversation to buffer.N)rI   asave_contextaprunerL   s      r   rP   -ConversationSummaryBufferMemory.asave_contextg   s2      g#F444kkm 	5s   848688c                    U R                   R                  nU R                  R                  U5      nX R                  :  a  / nX R                  :  aL  UR                  UR                  S5      5        U R                  R                  U5      nX R                  :  a  ML  U R                  UU R                  5      U l        gg)z*Prune buffer if it exceeds max token limitr   N)	r-   r.   llmget_num_tokens_from_messagesr   appendpoppredict_new_summaryr   r   r   curr_buffer_lengthpruned_memorys       r   rK   %ConversationSummaryBufferMemory.prunep   s    !!**!XXBB6J 4 44M$';';;$$VZZ]3%)XX%J%J6%R" %';';; *.)A)A***D& 5r   c                   #    U R                   R                  nU R                  R                  U5      nX R                  :  a  / nX R                  :  aL  UR                  UR                  S5      5        U R                  R                  U5      nX R                  :  a  ML  U R                  UU R                  5      I Sh  vN U l        gg N7f)z9Asynchronously prune buffer if it exceeds max token limitr   N)	r-   r.   rT   rU   r   rV   rW   apredict_new_summaryr   rY   s       r   rQ   &ConversationSummaryBufferMemory.aprune~   s     !!**!XXBB6J 4 44M$';';;$$VZZ]3%)XX%J%J6%R" %';';; 04/H/H**0 *D& 5
*s   BC C?C Cc                 0   > [         TU ]  5         SU l        g)zClear memory contents.r   N)rI   clearr   r   rM   s    r   ra   %ConversationSummaryBufferMemory.clear   s    %'"r   c                 L   >#    [         TU ]  5       I Sh  vN   SU l        g N7f)z%Asynchronously clear memory contents.Nr   )rI   aclearr   rb   s    r   re   &ConversationSummaryBufferMemory.aclear   s#     gn%'" 	s   $"$)r   )r   N) __name__
__module____qualname____firstlineno____doc__r   int__annotations__r   strr   propertyr   listr   r   r"   r!   dictr   r   r    r   rE   rJ   rP   rK   rQ   ra   re   __static_attributes____classcell__)rM   s   @r   r   r      sh     OS!#3#J?c4#445 ? ?1uS${*;%;< 1
 !$s) ! !/DcN /tCH~ /$/4S> /d3PS8n /$ 
T 
d 
 
4S> DcN t 
S#X c3h 
	(
( (r   r   N)typingr   r   langchain_core._apir   langchain_core.messagesr   r   langchain_core.utilsr   langchain.memory.chat_memoryr	   langchain.memory.summaryr
   r    r   r   <module>r{      sH     * B ) 7 4 
	G	A(no A(A(r   