
    hh                        d dl mZ d dlmZmZmZ d dlmZ 	 d dlm	Z	  G d de	          Z
dS # e$ r  G d d          Z
Y dS w xY w)	    )annotations)AnyDictOptional)ZepChatMessageHistory)ConversationBufferMemoryc                  N     e Zd ZU dZded<   	 	 	 	 	 	 	 	 d d! fdZ	 d"d#dZ xZS )$	ZepMemorya*  Persist your chain history to the Zep MemoryStore.

        The number of messages returned by Zep and when the Zep server summarizes chat
        histories is configurable. See the Zep documentation for more details.

        Documentation: https://docs.getzep.com

        Example:
            .. code-block:: python

            memory = ZepMemory(
                        session_id=session_id,  # Identifies your user or a user's session
                        url=ZEP_API_URL,        # Your Zep server's URL
                        api_key=<your_api_key>, # Optional
                        memory_key="history",   # Ensure this matches the key used in
                                                # chain's prompt template
                        return_messages=True,   # Does your prompt template expect a string
                                                # or a list of Messages?
                    )
            chain = LLMChain(memory=memory,...) # Configure your chain to use the ZepMemory
                                                  instance


        Note:
            To persist metadata alongside your chat history, your will need to create a
        custom Chain class that overrides the `prep_outputs` method to include the metadata
        in the call to `self.memory.save_context`.


        Zep - Fast, scalable building blocks for LLM Apps
        =========
        Zep is an open source platform for productionizing LLM apps. Go from a prototype
        built in LangChain or LlamaIndex, or a custom app, to production in minutes without
        rewriting code.

        For server installation instructions and more, see:
        https://docs.getzep.com/deployment/quickstart/

        For more information on the zep-python package, see:
        https://github.com/getzep/zep-python

        r   chat_memoryhttp://localhost:8000NFHumanAIhistory
session_idstrurlapi_keyOptional[str]
output_key	input_keyreturn_messagesboolhuman_prefix	ai_prefix
memory_keyc
           	     |    t          |||          }
t                                          |
||||||	           dS )a  Initialize ZepMemory.

            Args:
                session_id (str): Identifies your user or a user's session
                url (str, optional): Your Zep server's URL. Defaults to
                                     "http://localhost:8000".
                api_key (Optional[str], optional): Your Zep API key. Defaults to None.
                output_key (Optional[str], optional): The key to use for the output message.
                                                  Defaults to None.
                input_key (Optional[str], optional): The key to use for the input message.
                                                  Defaults to None.
                return_messages (bool, optional): Does your prompt template expect a string
                                                  or a list of Messages? Defaults to False
                                                  i.e. return a string.
                human_prefix (str, optional): The prefix to use for human messages.
                                              Defaults to "Human".
                ai_prefix (str, optional): The prefix to use for AI messages.
                                           Defaults to "AI".
                memory_key (str, optional): The key to use for the memory.
                                            Defaults to "history".
                                            Ensure that this matches the key used in
                                            chain's prompt template.
            )r   r   r   )r   r   r   r   r   r   r   N)r   super__init__)selfr   r   r   r   r   r   r   r   r   chat_message_history	__class__s              b/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_community/memory/zep_memory.pyr   zZepMemory.__init__8   sf    F $9%$ $ $ 
 GG0%# /)#%          inputsDict[str, Any]outputsDict[str, str]metadataOptional[Dict[str, Any]]returnNonec                    |                      ||          \  }}| j                            ||           | j                            ||           dS )a  Save context from this conversation to buffer.

            Args:
                inputs (Dict[str, Any]): The inputs to the chain.
                outputs (Dict[str, str]): The outputs from the chain.
                metadata (Optional[Dict[str, Any]], optional): Any metadata to save with
                                                           the context. Defaults to None

            Returns:
                None
            )r(   N)_get_input_outputr   add_user_messageadd_ai_message)r   r$   r&   r(   	input_str
output_strs         r"   save_contextzZepMemory.save_contextj   s\    " %)$:$:67$K$K!Iz--i(-KKK++J+JJJJJr#   )r   NNNFr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )N)r$   r%   r&   r'   r(   r)   r*   r+   )__name__
__module____qualname____doc____annotations__r   r2   __classcell__)r!   s   @r"   r
   r
   
   s         )	 )	V 	+***
 /%)(,'+$) '!'0	 0	 0	 0	 0	 0	 0	l 26		K 	K 	K 	K 	K 	K 	K 	K 	Kr#   r
   c                      e Zd ZdS )r
   N)r3   r4   r5    r#   r"   r
   r
      s        r#   N)
__future__r   typingr   r   r   *langchain_community.chat_message_historiesr   langchain.memoryr   r
   ImportErrorr:   r#   r"   <module>r@      s    " " " " " " & & & & & & & & & & L L L L L L{999999sK sK sK sK sK, sK sK sK sK sKj              s   . AA