2025-06-23 12:19:32 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎虎
|
|
|
|
|
|
@file: chat_record.py
|
|
|
|
|
|
@date:2025/6/23 10:42
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
2025-06-23 13:28:10 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2025-06-23 12:19:32 +00:00
|
|
|
|
from drf_spectacular.utils import extend_schema
|
|
|
|
|
|
from rest_framework.request import Request
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
2025-06-23 13:28:10 +00:00
|
|
|
|
from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI
|
2025-06-23 12:19:32 +00:00
|
|
|
|
from chat.api.vote_api import VoteAPI
|
2025-06-23 13:28:10 +00:00
|
|
|
|
from chat.serializers.chat_record import VoteSerializer, ChatRecordSerializer
|
2025-06-23 12:19:32 +00:00
|
|
|
|
from common import result
|
|
|
|
|
|
from common.auth import TokenAuth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VoteView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
|
|
|
|
|
methods=['PUT'],
|
|
|
|
|
|
description=_("Like, Dislike"),
|
|
|
|
|
|
summary=_("Like, Dislike"),
|
|
|
|
|
|
operation_id=_("Like, Dislike"), # type: ignore
|
|
|
|
|
|
parameters=VoteAPI.get_parameters(),
|
|
|
|
|
|
request=VoteAPI.get_request(),
|
|
|
|
|
|
responses=VoteAPI.get_response(),
|
|
|
|
|
|
tags=[_('Chat')] # type: ignore
|
|
|
|
|
|
)
|
|
|
|
|
|
def put(self, request: Request, chat_id: str, chat_record_id: str):
|
|
|
|
|
|
return result.success(VoteSerializer(
|
|
|
|
|
|
data={'chat_id': chat_id,
|
|
|
|
|
|
'chat_record_id': chat_record_id
|
|
|
|
|
|
}).vote(request.data))
|
2025-06-23 13:28:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HistoricalConversationView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
|
|
|
|
|
methods=['GET'],
|
|
|
|
|
|
description=_("Get historical conversation"),
|
|
|
|
|
|
summary=_("Get historical conversation"),
|
|
|
|
|
|
operation_id=_("Get historical conversation"), # type: ignore
|
|
|
|
|
|
parameters=HistoricalConversationAPI.get_parameters(),
|
|
|
|
|
|
responses=HistoricalConversationAPI.get_response(),
|
|
|
|
|
|
tags=[_('Chat')] # type: ignore
|
|
|
|
|
|
)
|
|
|
|
|
|
def get(self, request: Request):
|
|
|
|
|
|
return result.success(ChatRecordSerializer(
|
|
|
|
|
|
data={
|
|
|
|
|
|
'application_id': request.auth.application_id,
|
|
|
|
|
|
'chat_user_id': request.auth.chat_user_id,
|
|
|
|
|
|
}).list())
|
|
|
|
|
|
|
|
|
|
|
|
class PageView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
|
|
|
|
|
methods=['GET'],
|
|
|
|
|
|
description=_("Get historical conversation by page"),
|
|
|
|
|
|
summary=_("Get historical conversation by page"),
|
|
|
|
|
|
operation_id=_("Get historical conversation by page"), # type: ignore
|
|
|
|
|
|
parameters=PageHistoricalConversationAPI.get_parameters(),
|
|
|
|
|
|
responses=PageHistoricalConversationAPI.get_response(),
|
|
|
|
|
|
tags=[_('Chat')] # type: ignore
|
|
|
|
|
|
)
|
|
|
|
|
|
def get(self, request: Request, current_page: int, page_size: int):
|
|
|
|
|
|
return result.success(ChatRecordSerializer(
|
|
|
|
|
|
data={
|
|
|
|
|
|
'application_id': request.auth.application_id,
|
|
|
|
|
|
'chat_user_id': request.auth.chat_user_id,
|
|
|
|
|
|
}).page(current_page, page_size))
|