Spaces:
Sleeping
Sleeping
Download memory.py from Shrouk04/customer_support_agent2: direct link, hf CLI and curl.
- Browser
- Download file 756 Bytes
-
https://huggingface.co/spaces/Shrouk04/customer_support_agent2/resolve/main/memory.py
- Command line
-
hf download hf://spaces/Shrouk04/customer_support_agent2/memory.py
-
curl -L -o memory.py https://huggingface.co/spaces/Shrouk04/customer_support_agent2/resolve/main/memory.py
756 Bytes
| class ConversationMemory: | |
| def __init__(self, max_messages=10): | |
| self.max_messages = max_messages | |
| self.messages = [] | |
| def add_user_message(self, text): | |
| self.messages.append({ | |
| "role": "user", | |
| "content": text | |
| }) | |
| self._trim() | |
| def add_assistant_message(self, text): | |
| self.messages.append({ | |
| "role": "assistant", | |
| "content": text | |
| }) | |
| self._trim() | |
| def get_memory(self): | |
| return self.messages | |
| def clear(self): | |
| self.messages = [] | |
| def _trim(self): | |
| if len(self.messages) > self.max_messages: | |
| self.messages = self.messages[-self.max_messages:] |