From 4b4691d68993c287fad1936a8dc1cb58287cba45 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Fri, 27 Jun 2025 18:54:05 +0800 Subject: [PATCH] feat: Chat record details (#3418) --- apps/chat/urls.py | 1 + apps/chat/views/chat_record.py | 23 +++++++++++++ ui/src/api/chat/chat.ts | 22 +++++++++++-- ui/src/components/ai-chat/index.vue | 51 ++++++++++++++++++----------- 4 files changed, 74 insertions(+), 23 deletions(-) diff --git a/apps/chat/urls.py b/apps/chat/urls.py index 45a20ce36..aee74c83e 100644 --- a/apps/chat/urls.py +++ b/apps/chat/urls.py @@ -14,6 +14,7 @@ urlpatterns = [ path('captcha', views.CaptchaView.as_view(), name='captcha'), path('vote/chat//chat_record/', views.VoteView.as_view(), name='vote'), path('historical_conversation', views.HistoricalConversationView.as_view(), name='historical_conversation'), + path('historical_conversation//record/',views.ChatRecordView.as_view(),name='conversation_details'), path('historical_conversation//', views.HistoricalConversationView.PageView.as_view(), name='historical_conversation'), path('historical_conversation_record/', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'), path('historical_conversation_record///', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record') diff --git a/apps/chat/views/chat_record.py b/apps/chat/views/chat_record.py index f480d55cf..06a71077f 100644 --- a/apps/chat/views/chat_record.py +++ b/apps/chat/views/chat_record.py @@ -11,6 +11,7 @@ from drf_spectacular.utils import extend_schema from rest_framework.request import Request from rest_framework.views import APIView +from application.serializers.application_chat_record import ChatRecordOperateSerializer from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI, \ PageHistoricalConversationRecordAPI, HistoricalConversationRecordAPI from chat.api.vote_api import VoteAPI @@ -118,3 +119,25 @@ class HistoricalConversationRecordView(APIView): 'application_id': request.auth.application_id, 'chat_user_id': request.auth.chat_user_id, }).page(current_page, page_size)) + + +class ChatRecordView(APIView): + authentication_classes = [TokenAuth] + + @extend_schema( + methods=['GET'], + description=_("Get conversation details"), + summary=_("Get conversation details"), + operation_id=_("Get conversation details"), # type: ignore + parameters=PageHistoricalConversationRecordAPI.get_parameters(), + responses=PageHistoricalConversationRecordAPI.get_response(), + tags=[_('Chat')] # type: ignore + ) + def get(self, request: Request, chat_id: str, chat_record_id: str): + return result.success(ChatRecordOperateSerializer( + data={ + 'chat_id': chat_id, + 'chat_record_id': chat_record_id, + 'application_id': request.auth.application_id, + 'chat_user_id': request.auth.chat_user_id, + }).one(True)) diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index 3baa31bdc..eab5ed591 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -11,7 +11,7 @@ import { } from '@/request/chat/index' import { type ChatProfile } from '@/api/type/chat' import { type Ref } from 'vue' -import type { ResetPasswordRequest } from "@/api/type/user.ts"; +import type { ResetPasswordRequest } from '@/api/type/user.ts' import useStore from '@/stores' import type { LoginRequest } from '@/api/type/user' @@ -219,7 +219,7 @@ const logout: (loading?: Ref) => Promise> = (loading) = */ const resetCurrentPassword: ( request: ResetPasswordRequest, - loading?: Ref + loading?: Ref, ) => Promise> = (request, loading) => { return post('/chat_user/current/reset_password', request, undefined, loading) } @@ -230,6 +230,21 @@ const resetCurrentPassword: ( const getChatUserProfile: (loading?: Ref) => Promise> = (loading) => { return get('/chat_user/profile', {}, loading) } +/** + * 获取对话详情 + * @param chat_id 对话id + * @param chat_record_id 对话记录id + * @param loading 加载器 + * @returns + */ +const getChatRecord: ( + chat_id: string, + chat_record_id: string, + loading?: Ref, +) => Promise> = (chat_id, chat_record_id, loading) => { + return get(`historical_conversation/${chat_id}/record/${chat_record_id}`, {}, loading) +} + export default { open, chat, @@ -252,5 +267,6 @@ export default { pageChatRecord, logout, resetCurrentPassword, - getChatUserProfile + getChatUserProfile, + getChatRecord, } diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 655ee624f..6df7c2aa7 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -312,6 +312,37 @@ const getOpenChatAPI = () => { } } } + +/** + * 获取对话详情 + * @param row + */ +function getSourceDetail(row: any) { + if (row.record_id) { + if (props.type === 'debug-ai-chat') { + chatLogApi + .getChatRecordDetails(id || props.appId, row.chat_id, row.record_id, loading) + .then((res) => { + const exclude_keys = ['answer_text', 'id', 'answer_text_list'] + Object.keys(res.data).forEach((key) => { + if (!exclude_keys.includes(key)) { + row[key] = res.data[key] + } + }) + }) + } else { + chatAPI.getChatRecord(row.chat_id, row.record_id, loading).then((res) => { + const exclude_keys = ['answer_text', 'id', 'answer_text_list'] + Object.keys(res.data).forEach((key) => { + if (!exclude_keys.includes(key)) { + row[key] = res.data[key] + } + }) + }) + } + } + return true +} /** * 对话 */ @@ -511,26 +542,6 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para } } -/** - * 获取对话详情 - * @param row - */ -function getSourceDetail(row: any) { - if (row.record_id) { - chatLogApi - .getChatRecordDetails(id || props.appId, row.chat_id, row.record_id, loading) - .then((res) => { - const exclude_keys = ['answer_text', 'id', 'answer_text_list'] - Object.keys(res.data).forEach((key) => { - if (!exclude_keys.includes(key)) { - row[key] = res.data[key] - } - }) - }) - } - return true -} - /** * 滚动条距离最上面的高度 */