Spaces:
Sleeping
Sleeping
Download api/memory.py from chemenovausa/orbitchem-api: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/api/memory.py
- Command line
-
hf download hf://spaces/chemenovausa/orbitchem-api/api/memory.py
-
curl -L -o memory.py https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/api/memory.py
1.2 kB
| """ | |
| api/memory.py | |
| Bridge: exposes the FormulationMemoryNetwork as the `memory` singleton | |
| used throughout the API (controller.py, main.py, odata endpoints). | |
| Replaces the previous 21-line MemoryBus stub with the full 568-line | |
| engine from modules/memory_network.py. | |
| """ | |
| import types | |
| from modules.memory_network import get_memory_network | |
| # Module-level singleton β same interface the rest of the app expects | |
| memory = get_memory_network() | |
| # ββ Add the thin compat methods the rest of the app still calls ββββββββββββββββ | |
| # (FormulationMemoryNetwork already has .record() with matching positional args) | |
| def _recent(self, n=10): | |
| """Return last n events (MemoryBus compat).""" | |
| return self.state.events[-n:] | |
| def _query(self, filter_fn): | |
| """Filter events by predicate (MemoryBus compat).""" | |
| return [e for e in self.state.events if filter_fn(e)] | |
| def _get_all(self): | |
| """Return all recorded events.""" | |
| return self.state.events | |
| # Bind as instance methods (self will be passed correctly) | |
| memory.recent = types.MethodType(_recent, memory) | |
| memory.query = types.MethodType(_query, memory) | |
| memory.get_all = types.MethodType(_get_all, memory) | |