Run the MemChat.
(self)
| 35 | self._mem_cube = value |
| 36 | |
| 37 | def run(self) -> None: |
| 38 | """Run the MemChat.""" |
| 39 | |
| 40 | # Start MemChat |
| 41 | |
| 42 | print( |
| 43 | "\n📢 [System] " + "Simple MemChat is running.\n" |
| 44 | "Commands: 'bye' to quit, 'clear' to clear chat history, 'mem' to show all memories, 'export' to export chat history\n", |
| 45 | ) |
| 46 | |
| 47 | messages = [] |
| 48 | while True: |
| 49 | # Get user input |
| 50 | |
| 51 | user_input = input("👤 [You] ").strip() |
| 52 | print() |
| 53 | |
| 54 | if user_input.lower() == "bye": |
| 55 | break |
| 56 | elif user_input.lower() == "clear": |
| 57 | messages = [] |
| 58 | print("📢 [System] Chat history cleared.") |
| 59 | continue |
| 60 | elif user_input.lower() == "mem": |
| 61 | if self.config.enable_textual_memory: |
| 62 | all_memories = self.mem_cube.text_mem.get_all() |
| 63 | print(f"🧠 [Memory] \n{self._str_memories(all_memories)}\n") |
| 64 | else: |
| 65 | print("📢 [System] Textual memory is not enabled.\n") |
| 66 | continue |
| 67 | elif user_input.lower() == "export": |
| 68 | if messages: |
| 69 | filepath = self._export_chat_history(messages) |
| 70 | print(f"📢 [System] Chat history exported to: {filepath}\n") |
| 71 | else: |
| 72 | print("📢 [System] No chat history to export.\n") |
| 73 | continue |
| 74 | elif user_input == "": |
| 75 | continue |
| 76 | |
| 77 | # Get memories |
| 78 | |
| 79 | if self.config.enable_textual_memory: |
| 80 | memories = self.mem_cube.text_mem.search(user_input, top_k=self.config.top_k) |
| 81 | print( |
| 82 | f"🧠 [Memory] Searched memories:\n{self._str_memories(memories, mode='concise')}\n" |
| 83 | ) |
| 84 | system_prompt = self._build_system_prompt(memories) |
| 85 | else: |
| 86 | system_prompt = self._build_system_prompt() |
| 87 | current_messages = [ |
| 88 | {"role": "system", "content": system_prompt}, |
| 89 | *messages, |
| 90 | {"role": "user", "content": user_input}, |
| 91 | ] |
| 92 | |
| 93 | if self.config.enable_activation_memory: |
| 94 | past_key_values = None |
nothing calls this directly
no test coverage detected