Super basic doc chat

[ci skip]
This commit is contained in:
shamoon
2025-04-24 23:41:31 -07:00
parent e2eec6dc71
commit d1bd2af49c
4 changed files with 47 additions and 8 deletions

View File

@@ -173,6 +173,7 @@ from documents.templating.filepath import validate_filepath_template_and_render
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.matching import extract_unmatched_names
from paperless.ai.matching import match_correspondents_by_name
from paperless.ai.matching import match_document_types_by_name
@@ -1167,6 +1168,17 @@ class DocumentViewSet(
"Error emailing document, check logs for more detail.",
)
@action(methods=["post"], detail=False, url_path="chat")
def chat(self, request):
ai_config = AIConfig()
if not ai_config.ai_enabled:
return HttpResponseBadRequest("AI is required for this feature")
question = request.data["q"]
result = chat_with_documents(question, request.user)
return Response({"answer": result})
@extend_schema_view(
list=extend_schema(