@@ -49,21 +49,19 @@ memory = Memory()
4949# Set up your OpenAI client like you normally would.
5050# This example assumes that the OpenAI key is stored in the OPENAI_API_KEY
5151# environment variable.
52- openai_client = OpenAI(api_key = " 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 " )
52+ openai_client = OpenAI()
5353
5454def chat_with_memories (message : str , user_id : str = " default_user" ) -> str :
5555 # Retrieve the user memory block if it exists, otherwise initialize it
5656 # User memory blocks are pieces of information about whoever is talking
5757 # to your assistant, and can be created/retrieved using arbitrary string
58- # keys.
58+ # identifier keys.
5959 user_memory = memory.get_user_memory(user_id)
6060 if not user_memory:
6161 # User doesn't exist, create a new memory block
6262 memory.initialize_user_memory(user_id, reset = True )
6363 user_memory = memory.get_user_memory(user_id)
6464
65-
66- # memory.get_user_memory(user_id, prompt_formatted=True) returns
6765 # the contents of the user block formatted as a prompt:
6866 #
6967 # <human description="Details about the human user you are speaking to.">
@@ -93,7 +91,8 @@ def chat_with_memories(message: str, user_id: str = "default_user") -> str:
9391 # Extract the assistant's message from the API response
9492 assistant_response = response.choices[0 ].message.content
9593
96- # Create new memories from the conversation -- this will update the user's memory block
94+ # Create new memories from the conversation --
95+ # this will update the user's memory block and persist messages
9796 print (" Creating new memories..." )
9897 messages.append({" role" : " assistant" , " content" : assistant_response})
9998 memory.add_messages(user_id, messages)
0 commit comments