Download plugins/memory/document_memory.py from JatinAutonomousLabs/Excel_AI_Assistant: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/spaces/JatinAutonomousLabs/Excel_AI_Assistant/resolve/main/plugins/memory/document_memory.py
- Command line
-
hf download hf://spaces/JatinAutonomousLabs/Excel_AI_Assistant/plugins/memory/document_memory.py
-
curl -L -o document_memory.py https://huggingface.co/spaces/JatinAutonomousLabs/Excel_AI_Assistant/resolve/main/plugins/memory/document_memory.py
922 Bytes
| #!/usr/bin/env python3 | |
| """Document Memory Plugin""" | |
| from typing import Dict, Any, Optional | |
| class DocumentMemory: | |
| """Cache and manage uploaded documents.""" | |
| def __init__(self): | |
| self.documents = {} | |
| self.metadata = {} | |
| def store_document(self, doc_id: str, content: Any, metadata: Dict[str, Any]): | |
| """Store document with metadata.""" | |
| self.documents[doc_id] = content | |
| self.metadata[doc_id] = metadata | |
| def get_document(self, doc_id: str) -> Optional[Any]: | |
| """Retrieve document by ID.""" | |
| return self.documents.get(doc_id) | |
| def list_documents(self) -> Dict[str, Dict[str, Any]]: | |
| """List all stored documents with metadata.""" | |
| return {doc_id: self.metadata[doc_id] for doc_id in self.documents.keys()} | |
| def clear(self): | |
| """Clear all documents.""" | |
| self.documents.clear() | |
| self.metadata.clear() | |