Spaces:
Sleeping
Sleeping
Commit Β·
53abaec
1
Parent(s): d4b970f
fix(storage): add list_docs and set_document_tree aliases to MemoryStorage and fix chat.py call
Browse files- app/core/storage.py +18 -0
- app/routers/chat.py +1 -1
app/core/storage.py
CHANGED
|
@@ -558,12 +558,22 @@ class MemoryStorage:
|
|
| 558 |
results.append(d)
|
| 559 |
return results
|
| 560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
def get_document_tree(self, doc_id: str, owner_id: Optional[str] = None) -> Optional[Any]:
|
| 562 |
doc = self.get_document(doc_id, owner_id=owner_id)
|
| 563 |
if doc and doc.get("tree") is not None:
|
| 564 |
return doc["tree"]
|
| 565 |
return self._trees.get(doc_id) if owner_id is None else None
|
| 566 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
def delete_document(self, doc_id: str, owner_id: Optional[str] = None) -> bool:
|
| 568 |
if owner_id is not None:
|
| 569 |
doc = self.get_document(doc_id, owner_id=owner_id)
|
|
@@ -599,6 +609,14 @@ class MemoryStorage:
|
|
| 599 |
count += 1
|
| 600 |
return count
|
| 601 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
|
| 603 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 604 |
# Chat operations (backed by persistent DB)
|
|
|
|
| 558 |
results.append(d)
|
| 559 |
return results
|
| 560 |
|
| 561 |
+
def list_docs(self, owner_id: Optional[str] = None) -> List[Dict[str, Any]]:
|
| 562 |
+
"""Compatibility alias for list_documents."""
|
| 563 |
+
return self.list_documents(owner_id=owner_id)
|
| 564 |
+
|
| 565 |
def get_document_tree(self, doc_id: str, owner_id: Optional[str] = None) -> Optional[Any]:
|
| 566 |
doc = self.get_document(doc_id, owner_id=owner_id)
|
| 567 |
if doc and doc.get("tree") is not None:
|
| 568 |
return doc["tree"]
|
| 569 |
return self._trees.get(doc_id) if owner_id is None else None
|
| 570 |
|
| 571 |
+
def set_document_tree(self, doc_id: str, tree: Any) -> None:
|
| 572 |
+
"""Store document tree in memory cache."""
|
| 573 |
+
self._trees[doc_id] = tree
|
| 574 |
+
if doc_id in self._documents:
|
| 575 |
+
self._documents[doc_id]["tree"] = tree
|
| 576 |
+
|
| 577 |
def delete_document(self, doc_id: str, owner_id: Optional[str] = None) -> bool:
|
| 578 |
if owner_id is not None:
|
| 579 |
doc = self.get_document(doc_id, owner_id=owner_id)
|
|
|
|
| 609 |
count += 1
|
| 610 |
return count
|
| 611 |
|
| 612 |
+
def delete_doc(self, doc_id: str, owner_id: Optional[str] = None) -> bool:
|
| 613 |
+
"""Compatibility alias for delete_document."""
|
| 614 |
+
return self.delete_document(doc_id, owner_id=owner_id)
|
| 615 |
+
|
| 616 |
+
def delete_all_docs(self, owner_id: Optional[str] = None) -> int:
|
| 617 |
+
"""Compatibility alias for delete_all_documents."""
|
| 618 |
+
return self.delete_all_documents(owner_id=owner_id)
|
| 619 |
+
|
| 620 |
|
| 621 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 622 |
# Chat operations (backed by persistent DB)
|
app/routers/chat.py
CHANGED
|
@@ -176,7 +176,7 @@ async def ask_question(
|
|
| 176 |
|
| 177 |
# If no document is currently attached to this chat, check if the user explicitly mentioned a stored document
|
| 178 |
if not target_doc_ids:
|
| 179 |
-
all_stored_docs = storage.
|
| 180 |
q_lower = request.query.lower()
|
| 181 |
for doc in all_stored_docs:
|
| 182 |
fname = (doc.get("filename") or "").lower()
|
|
|
|
| 176 |
|
| 177 |
# If no document is currently attached to this chat, check if the user explicitly mentioned a stored document
|
| 178 |
if not target_doc_ids:
|
| 179 |
+
all_stored_docs = storage.list_documents(owner_id=client_id)
|
| 180 |
q_lower = request.query.lower()
|
| 181 |
for doc in all_stored_docs:
|
| 182 |
fname = (doc.get("filename") or "").lower()
|