mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-18 22:14:22 -06:00
Change view to API view
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import itertools
|
import itertools
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -21,7 +20,6 @@ import magic
|
|||||||
import pathvalidate
|
import pathvalidate
|
||||||
from celery import states
|
from celery import states
|
||||||
from django.conf import settings
|
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 Group
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
@@ -1337,25 +1335,26 @@ class DocumentViewSet(
|
|||||||
@method_decorator(
|
@method_decorator(
|
||||||
[
|
[
|
||||||
ensure_csrf_cookie,
|
ensure_csrf_cookie,
|
||||||
login_required,
|
|
||||||
cache_control(no_cache=True),
|
cache_control(no_cache=True),
|
||||||
],
|
],
|
||||||
name="dispatch",
|
name="dispatch",
|
||||||
)
|
)
|
||||||
class ChatStreamingView(View):
|
class ChatStreamingView(GenericAPIView):
|
||||||
def post(self, request):
|
permission_classes = (IsAuthenticated,)
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
request.compress_exempt = True
|
request.compress_exempt = True
|
||||||
ai_config = AIConfig()
|
ai_config = AIConfig()
|
||||||
if not ai_config.ai_enabled:
|
if not ai_config.ai_enabled:
|
||||||
return HttpResponseBadRequest("AI is required for this feature")
|
return HttpResponseBadRequest("AI is required for this feature")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(request.body)
|
question = request.data["q"]
|
||||||
question = data["q"]
|
except KeyError:
|
||||||
doc_id = data.get("document_id", None)
|
|
||||||
except (KeyError, json.JSONDecodeError):
|
|
||||||
return HttpResponseBadRequest("Invalid request")
|
return HttpResponseBadRequest("Invalid request")
|
||||||
|
|
||||||
|
doc_id = request.data.get("document_id")
|
||||||
|
|
||||||
if doc_id:
|
if doc_id:
|
||||||
try:
|
try:
|
||||||
document = Document.objects.get(id=doc_id)
|
document = Document.objects.get(id=doc_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user