Individual doc chat

[ci skip]
This commit is contained in:
shamoon
2025-04-24 23:56:51 -07:00
parent d1bd2af49c
commit ccfc7d98b1
2 changed files with 38 additions and 1 deletions

View File

@@ -174,6 +174,7 @@ from documents.utils import get_boolean
from paperless import version
from paperless.ai.ai_classifier import get_ai_document_classification
from paperless.ai.chat import chat_with_documents
from paperless.ai.chat import chat_with_single_document
from paperless.ai.matching import extract_unmatched_names
from paperless.ai.matching import match_correspondents_by_name
from paperless.ai.matching import match_document_types_by_name
@@ -1175,7 +1176,15 @@ class DocumentViewSet(
return HttpResponseBadRequest("AI is required for this feature")
question = request.data["q"]
result = chat_with_documents(question, request.user)
doc_id = request.data.get("document_id", None)
if doc_id:
document = Document.objects.get(id=doc_id)
if not has_perms_owner_aware(request.user, "view_document", document):
return HttpResponseForbidden("Insufficient permissions")
result = chat_with_single_document(document, question, request.user)
else:
result = chat_with_documents(question, request.user)
return Response({"answer": result})