Remove a memory from the store.
(self, prompt: str, llm: Any, threshold=1)
| 132 | return summarized_memory |
| 133 | |
| 134 | def remove_memory(self, prompt: str, llm: Any, threshold=1) -> None: |
| 135 | """Remove a memory from the store.""" |
| 136 | # update messages |
| 137 | for conversation in self.messages: |
| 138 | if conversation["prompt"] == prompt: |
| 139 | # updating messages |
| 140 | self.messages.remove(conversation) |
| 141 | |
| 142 | # updating other variables |
| 143 | self.current_summary = "" |
| 144 | self.current_buffer = "" |
| 145 | self.messages_in_buffer.clear() |
| 146 | self.messages_in_summary.clear() |
| 147 | |
| 148 | # get new messages in memory |
| 149 | new_messages = [ |
| 150 | item |
| 151 | for item in self.messages |
| 152 | if item not in self.messages_in_summary |
| 153 | and item not in self.messages_in_buffer |
| 154 | ] |
| 155 | |
| 156 | if len(new_messages) != 0: |
| 157 | # split conversations for buffer and summary according to threshold |
| 158 | buffer_messages = self.messages[-1 * threshold :] # buffer |
| 159 | summary_messages = [ |
| 160 | item for item in self.messages if item not in buffer_messages |
| 161 | ] # summary |
| 162 | |
| 163 | # get messages in the buffer format as text |
| 164 | self.current_buffer = "" |
| 165 | for conversation in buffer_messages: |
| 166 | self.current_buffer = ( |
| 167 | self.current_buffer |
| 168 | + "Human: " |
| 169 | + conversation["prompt"] |
| 170 | + "\n" |
| 171 | + "AI: " |
| 172 | + conversation["llm_response"] |
| 173 | + "\n" |
| 174 | ) |
| 175 | self.messages_in_buffer = buffer_messages |
| 176 | |
| 177 | # get the new messages to be added in the summary |
| 178 | additions_to_summary = [ |
| 179 | item |
| 180 | for item in summary_messages |
| 181 | if item not in self.messages_in_summary |
| 182 | ] |
| 183 | |
| 184 | if len(additions_to_summary) != 0: |
| 185 | additions_to_summary_as_text = "" |
| 186 | print(additions_to_summary_as_text) |
| 187 | |
| 188 | for conversation in additions_to_summary: |
| 189 | additions_to_summary_as_text = ( |
| 190 | additions_to_summary_as_text |
| 191 | + "Human: " |
nothing calls this directly
no test coverage detected