feat: Application conversation
This commit is contained in:
parent
e61e4eb937
commit
1ef0146389
@ -11,9 +11,9 @@ from drf_spectacular.utils import OpenApiParameter
|
|||||||
|
|
||||||
from application.serializers.application_chat_record import ChatRecordSerializerModel
|
from application.serializers.application_chat_record import ChatRecordSerializerModel
|
||||||
from chat.serializers.chat import ChatMessageSerializers
|
from chat.serializers.chat import ChatMessageSerializers
|
||||||
from chat.serializers.chat_record import HistoryChatModel
|
from chat.serializers.chat_record import HistoryChatModel, EditAbstractSerializer
|
||||||
from common.mixins.api_mixin import APIMixin
|
from common.mixins.api_mixin import APIMixin
|
||||||
from common.result import ResultSerializer, ResultPageSerializer
|
from common.result import ResultSerializer, ResultPageSerializer, DefaultResultSerializer
|
||||||
|
|
||||||
|
|
||||||
class ChatAPI(APIMixin):
|
class ChatAPI(APIMixin):
|
||||||
@ -72,6 +72,26 @@ class PageHistoricalConversationAPI(APIMixin):
|
|||||||
return PageApplicationCreateResponse
|
return PageApplicationCreateResponse
|
||||||
|
|
||||||
|
|
||||||
|
class HistoricalConversationOperateAPI(APIMixin):
|
||||||
|
@staticmethod
|
||||||
|
def get_parameters():
|
||||||
|
return [OpenApiParameter(
|
||||||
|
name="chat_id",
|
||||||
|
description="对话id",
|
||||||
|
type=OpenApiTypes.STR,
|
||||||
|
location='path',
|
||||||
|
required=True
|
||||||
|
)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_request():
|
||||||
|
return EditAbstractSerializer
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_response():
|
||||||
|
return DefaultResultSerializer
|
||||||
|
|
||||||
|
|
||||||
class HistoricalConversationRecordAPI(APIMixin):
|
class HistoricalConversationRecordAPI(APIMixin):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_parameters():
|
def get_parameters():
|
||||||
|
|||||||
@ -96,6 +96,39 @@ class HistoricalConversationSerializer(serializers.Serializer):
|
|||||||
return page_search(current_page, page_size, self.get_queryset(), lambda r: HistoryChatModel(r).data)
|
return page_search(current_page, page_size, self.get_queryset(), lambda r: HistoryChatModel(r).data)
|
||||||
|
|
||||||
|
|
||||||
|
class EditAbstractSerializer(serializers.Serializer):
|
||||||
|
abstract = serializers.CharField(required=True, label=_('Abstract'))
|
||||||
|
|
||||||
|
|
||||||
|
class HistoricalConversationOperateSerializer(serializers.Serializer):
|
||||||
|
application_id = serializers.UUIDField(required=True, label=_('Application ID'))
|
||||||
|
chat_user_id = serializers.UUIDField(required=True, label=_('Chat User ID'))
|
||||||
|
chat_id = serializers.UUIDField(required=True, label=_('Chat ID'))
|
||||||
|
|
||||||
|
def is_valid(self, *, raise_exception=False):
|
||||||
|
super().is_valid(raise_exception=True)
|
||||||
|
e = QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id'),
|
||||||
|
chat_user_id=self.data.get('chat_user_id')).exists()
|
||||||
|
if not e:
|
||||||
|
raise AppApiException(500, _('Chat is not exist'))
|
||||||
|
|
||||||
|
def edit_abstract(self, instance, with_valid=True):
|
||||||
|
if with_valid:
|
||||||
|
self.is_valid(raise_exception=True)
|
||||||
|
EditAbstractSerializer(data=instance).is_valid(raise_exception=True)
|
||||||
|
|
||||||
|
QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id'),
|
||||||
|
chat_user_id=self.data.get('chat_user_id')).update(abstract=instance.get('abstract'))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def logic_delete(self, with_valid=True):
|
||||||
|
if with_valid:
|
||||||
|
self.is_valid(raise_exception=True)
|
||||||
|
QuerySet(Chat).filter(id=self.data.get('chat_id'), application_id=self.data.get('application_id'),
|
||||||
|
chat_user_id=self.data.get('chat_user_id')).update(is_deleted=True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class HistoricalConversationRecordSerializer(serializers.Serializer):
|
class HistoricalConversationRecordSerializer(serializers.Serializer):
|
||||||
application_id = serializers.UUIDField(required=True, label=_('Application ID'))
|
application_id = serializers.UUIDField(required=True, label=_('Application ID'))
|
||||||
chat_id = serializers.UUIDField(required=True, label=_('Chat ID'))
|
chat_id = serializers.UUIDField(required=True, label=_('Chat ID'))
|
||||||
|
|||||||
@ -18,6 +18,7 @@ urlpatterns = [
|
|||||||
path('historical_conversation', views.HistoricalConversationView.as_view(), name='historical_conversation'),
|
path('historical_conversation', views.HistoricalConversationView.as_view(), name='historical_conversation'),
|
||||||
path('historical_conversation/<str:chat_id>/record/<str:chat_record_id>',views.ChatRecordView.as_view(),name='conversation_details'),
|
path('historical_conversation/<str:chat_id>/record/<str:chat_record_id>',views.ChatRecordView.as_view(),name='conversation_details'),
|
||||||
path('historical_conversation/<int:current_page>/<int:page_size>', views.HistoricalConversationView.PageView.as_view(), name='historical_conversation'),
|
path('historical_conversation/<int:current_page>/<int:page_size>', views.HistoricalConversationView.PageView.as_view(), name='historical_conversation'),
|
||||||
|
path('historical_conversation/<str:chat_id>',views.HistoricalConversationView.Operate.as_view(), name='historical_conversation_operate'),
|
||||||
path('historical_conversation_record/<str:chat_id>', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'),
|
path('historical_conversation_record/<str:chat_id>', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'),
|
||||||
path('historical_conversation_record/<str:chat_id>/<int:current_page>/<int:page_size>', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record')
|
path('historical_conversation_record/<str:chat_id>/<int:current_page>/<int:page_size>', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record')
|
||||||
]
|
]
|
||||||
|
|||||||
@ -13,10 +13,10 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
from application.serializers.application_chat_record import ChatRecordOperateSerializer
|
from application.serializers.application_chat_record import ChatRecordOperateSerializer
|
||||||
from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI, \
|
from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI, \
|
||||||
PageHistoricalConversationRecordAPI, HistoricalConversationRecordAPI
|
PageHistoricalConversationRecordAPI, HistoricalConversationRecordAPI, HistoricalConversationOperateAPI
|
||||||
from chat.api.vote_api import VoteAPI
|
from chat.api.vote_api import VoteAPI
|
||||||
from chat.serializers.chat_record import VoteSerializer, HistoricalConversationSerializer, \
|
from chat.serializers.chat_record import VoteSerializer, HistoricalConversationSerializer, \
|
||||||
HistoricalConversationRecordSerializer
|
HistoricalConversationRecordSerializer, HistoricalConversationOperateSerializer
|
||||||
from common import result
|
from common import result
|
||||||
from common.auth import TokenAuth
|
from common.auth import TokenAuth
|
||||||
|
|
||||||
@ -60,6 +60,45 @@ class HistoricalConversationView(APIView):
|
|||||||
'chat_user_id': request.auth.chat_user_id,
|
'chat_user_id': request.auth.chat_user_id,
|
||||||
}).list())
|
}).list())
|
||||||
|
|
||||||
|
class Operate(APIView):
|
||||||
|
authentication_classes = [TokenAuth]
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
methods=['PUT'],
|
||||||
|
description=_("Modify conversation about"),
|
||||||
|
summary=_("Modify conversation about"),
|
||||||
|
operation_id=_("Modify conversation about"), # type: ignore
|
||||||
|
parameters=HistoricalConversationOperateAPI.get_parameters(),
|
||||||
|
request=HistoricalConversationOperateAPI.get_request(),
|
||||||
|
responses=HistoricalConversationOperateAPI.get_response(),
|
||||||
|
tags=[_('Chat')] # type: ignore
|
||||||
|
)
|
||||||
|
def put(self, request: Request, chat_id: str):
|
||||||
|
return result.success(HistoricalConversationOperateSerializer(
|
||||||
|
data={
|
||||||
|
'application_id': request.auth.application_id,
|
||||||
|
'chat_user_id': request.auth.chat_user_id,
|
||||||
|
'chat_id': chat_id,
|
||||||
|
}).edit_abstract(request.data)
|
||||||
|
)
|
||||||
|
|
||||||
|
@extend_schema(
|
||||||
|
methods=['DELETE'],
|
||||||
|
description=_("Delete history conversation"),
|
||||||
|
summary=_("Delete history conversation"),
|
||||||
|
operation_id=_("Delete history conversation"), # type: ignore
|
||||||
|
parameters=HistoricalConversationOperateAPI.get_parameters(),
|
||||||
|
responses=HistoricalConversationOperateAPI.get_response(),
|
||||||
|
tags=[_('Chat')] # type: ignore
|
||||||
|
)
|
||||||
|
def delete(self, request: Request, chat_id: str):
|
||||||
|
return result.success(HistoricalConversationOperateSerializer(
|
||||||
|
data={
|
||||||
|
'application_id': request.auth.application_id,
|
||||||
|
'chat_user_id': request.auth.chat_user_id,
|
||||||
|
'chat_id': chat_id,
|
||||||
|
}).logic_delete())
|
||||||
|
|
||||||
class PageView(APIView):
|
class PageView(APIView):
|
||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|
||||||
|
|||||||
@ -104,7 +104,7 @@ class ToolView(APIView):
|
|||||||
tags=[_('Tool')] # type: ignore
|
tags=[_('Tool')] # type: ignore
|
||||||
)
|
)
|
||||||
@has_permissions(
|
@has_permissions(
|
||||||
PermissionConstants.TOOL_EDIT.get_workspace_permission(),
|
PermissionConstants.TOOL_EDIT.get_workspace_permission(),PermissionConstants.TOOL_EDIT.get_workspace_permission_workspace_manage_role(),
|
||||||
RoleConstants.WORKSPACE_MANAGE.get_workspace_role(), ViewPermission([RoleConstants.USER.get_workspace_role()],
|
RoleConstants.WORKSPACE_MANAGE.get_workspace_role(), ViewPermission([RoleConstants.USER.get_workspace_role()],
|
||||||
[PermissionConstants.TOOL.get_workspace_tool_permission()],
|
[PermissionConstants.TOOL.get_workspace_tool_permission()],
|
||||||
CompareConstants.AND),
|
CompareConstants.AND),
|
||||||
|
|||||||
@ -264,6 +264,31 @@ const speechToText: (data: any, loading?: Ref<boolean>) => Promise<Result<any>>
|
|||||||
) => {
|
) => {
|
||||||
return post(`speech_to_text`, data, undefined, loading)
|
return post(`speech_to_text`, data, undefined, loading)
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param chat_id 对话ID
|
||||||
|
* @param loading
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const deleteChat: (chat_id:string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
|
chat_id,
|
||||||
|
loading,
|
||||||
|
) => {
|
||||||
|
return del(`historical_conversation/${chat_id}`, loading)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param chat_id 对话id
|
||||||
|
* @param data 对话简介
|
||||||
|
* @param loading
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const modifyChat: (chat_id:string, data:any, loading?: Ref<boolean> ) => Promise<Result<any>> = (
|
||||||
|
chat_id,data,loading
|
||||||
|
) => {
|
||||||
|
return put(`historical_conversation/${chat_id}`, data, undefined, loading)
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
open,
|
open,
|
||||||
chat,
|
chat,
|
||||||
@ -290,4 +315,6 @@ export default {
|
|||||||
getChatRecord,
|
getChatRecord,
|
||||||
textToSpeech,
|
textToSpeech,
|
||||||
speechToText,
|
speechToText,
|
||||||
|
deleteChat,
|
||||||
|
modifyChat
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog class="responsive-dialog" :title="$t('chat.editTitle')" v-model="dialogVisible"
|
||||||
class="responsive-dialog"
|
:close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true" append-to-body>
|
||||||
:title="$t('chat.editTitle')"
|
<el-form label-position="top" ref="fieldFormRef" :model="form" require-asterisk-position="right">
|
||||||
v-model="dialogVisible"
|
<el-form-item prop="abstract" :rules="[
|
||||||
:close-on-click-modal="false"
|
{
|
||||||
:close-on-press-escape="false"
|
required: true,
|
||||||
:destroy-on-close="true"
|
message: $t('common.inputPlaceholder'),
|
||||||
append-to-body
|
trigger: 'blur'
|
||||||
>
|
}
|
||||||
<el-form
|
]">
|
||||||
label-position="top"
|
<el-input v-model="form.abstract" maxlength="1024" show-word-limit type="textarea"
|
||||||
ref="fieldFormRef"
|
@blur="form.abstract = form.abstract.trim()" />
|
||||||
:model="form"
|
|
||||||
require-asterisk-position="right"
|
|
||||||
>
|
|
||||||
<el-form-item
|
|
||||||
prop="abstract"
|
|
||||||
:rules="[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: $t('common.inputPlaceholder'),
|
|
||||||
trigger: 'blur'
|
|
||||||
}
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<el-input
|
|
||||||
v-model="form.abstract"
|
|
||||||
maxlength="1024"
|
|
||||||
show-word-limit
|
|
||||||
type="textarea"
|
|
||||||
@blur="form.abstract = form.abstract.trim()"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@ -44,12 +24,9 @@
|
|||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref, watch } from 'vue'
|
import { ref } from 'vue'
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance } from 'element-plus'
|
||||||
import useStore from '@/stores'
|
import chatAPI from '@/api/chat/chat'
|
||||||
import { t } from '@/locales'
|
|
||||||
|
|
||||||
const { chatLog } = useStore()
|
|
||||||
const emit = defineEmits(['refresh'])
|
const emit = defineEmits(['refresh'])
|
||||||
|
|
||||||
const fieldFormRef = ref()
|
const fieldFormRef = ref()
|
||||||
@ -71,10 +48,11 @@ const open = (row: any, id: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const submit = async (formEl: FormInstance | undefined) => {
|
const submit = async (formEl: FormInstance | undefined) => {
|
||||||
|
|
||||||
if (!formEl) return
|
if (!formEl) return
|
||||||
await formEl.validate((valid) => {
|
await formEl.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
chatLog.asyncPutChatClientLog(applicationId.value, chatId.value, form.value, loading).then(() => {
|
chatAPI.modifyChat(chatId.value, form.value, loading).then(() => {
|
||||||
emit('refresh', chatId.value, form.value.abstract)
|
emit('refresh', chatId.value, form.value.abstract)
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
})
|
})
|
||||||
|
|||||||
@ -331,7 +331,7 @@ import { cloneDeep } from 'lodash'
|
|||||||
|
|
||||||
useResize()
|
useResize()
|
||||||
|
|
||||||
const { user, chatLog, common, chatUser } = useStore()
|
const { common, chatUser } = useStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const EditTitleDialogRef = ref()
|
const EditTitleDialogRef = ref()
|
||||||
@ -425,7 +425,7 @@ function refreshFieldTitle(chatId: string, abstract: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
function deleteLog(row: any) {
|
function deleteLog(row: any) {
|
||||||
chatLog.asyncDelChatClientLog(applicationDetail.value.id, row.id, left_loading).then(() => {
|
chatAPI.deleteChat(row.id, left_loading).then(() => {
|
||||||
if (currentChatId.value === row.id) {
|
if (currentChatId.value === row.id) {
|
||||||
currentChatId.value = 'new'
|
currentChatId.value = 'new'
|
||||||
currentChatName.value = t('chat.createChat')
|
currentChatName.value = t('chat.createChat')
|
||||||
@ -435,6 +435,7 @@ function deleteLog(row: any) {
|
|||||||
}
|
}
|
||||||
getChatLog(applicationDetail.value.id)
|
getChatLog(applicationDetail.value.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleScroll(event: any) {
|
function handleScroll(event: any) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user