From f9d7b821c399f9ddc0ac311e9b3f77a37f2356f5 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 9 Jan 2026 09:19:26 -0800 Subject: [PATCH] Change view to API view --- src/documents/views.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/documents/views.py b/src/documents/views.py index 0488de1d9..9e2805ad0 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1,5 +1,4 @@ import itertools -import json import logging import os import platform @@ -21,7 +20,6 @@ import magic import pathvalidate from celery import states from django.conf import settings -from django.contrib.auth.decorators import login_required from django.contrib.auth.models import Group from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType @@ -1337,25 +1335,26 @@ class DocumentViewSet( @method_decorator( [ ensure_csrf_cookie, - login_required, cache_control(no_cache=True), ], name="dispatch", ) -class ChatStreamingView(View): - def post(self, request): +class ChatStreamingView(GenericAPIView): + permission_classes = (IsAuthenticated,) + + def post(self, request, *args, **kwargs): request.compress_exempt = True ai_config = AIConfig() if not ai_config.ai_enabled: return HttpResponseBadRequest("AI is required for this feature") try: - data = json.loads(request.body) - question = data["q"] - doc_id = data.get("document_id", None) - except (KeyError, json.JSONDecodeError): + question = request.data["q"] + except KeyError: return HttpResponseBadRequest("Invalid request") + doc_id = request.data.get("document_id") + if doc_id: try: document = Document.objects.get(id=doc_id)