Cachinde
feat: Integracao total com modelo Llama 3 local e suporte a pesos LoRA usando ZeroGPU
f3200bb Download memory.py from akra35567/brain: direct link, hf CLI and curl.
- Browser
- Download file 986 Bytes
-
https://huggingface.co/spaces/akra35567/brain/resolve/main/memory.py
- Command line
-
hf download hf://spaces/akra35567/brain/memory.py
-
curl -L -o memory.py https://huggingface.co/spaces/akra35567/brain/resolve/main/memory.py
986 Bytes
| from collections import defaultdict, deque | |
| from typing import Deque, Dict, List | |
| class MemoryManager: | |
| """Hist贸rico curto por cliente, em mem贸ria (adequado a CPU-basic no HF Space).""" | |
| def __init__(self, max_history: int = 8): | |
| self.max_history = max_history | |
| self._store: Dict[str, Deque[dict]] = defaultdict(lambda: deque(maxlen=max_history)) | |
| def get_context(self, client_id: str) -> str: | |
| history = self._store.get(client_id) | |
| if not history: | |
| return "" | |
| lines: List[str] = ["Hist贸rico recente desta conversa:"] | |
| for item in history: | |
| role = "Cliente" if item["role"] == "user" else "Plenitude" | |
| lines.append(f"{role}: {item['content']}") | |
| return "\n".join(lines) | |
| def add_message(self, client_id: str, role: str, content: str) -> None: | |
| if not client_id or not content: | |
| return | |
| self._store[client_id].append({"role": role, "content": content.strip()}) | |