feat: Chat record details (#3418)

This commit is contained in:
shaohuzhang1 2025-06-27 18:54:05 +08:00 committed by GitHub
parent 22d86f046a
commit 4b4691d689
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 74 additions and 23 deletions

View File

@ -14,6 +14,7 @@ urlpatterns = [
path('captcha', views.CaptchaView.as_view(), name='captcha'),
path('vote/chat/<str:chat_id>/chat_record/<str:chat_record_id>', views.VoteView.as_view(), name='vote'),
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/<int:current_page>/<int:page_size>', views.HistoricalConversationView.PageView.as_view(), name='historical_conversation'),
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')

View File

@ -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))

View File

@ -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<boolean>) => Promise<Result<boolean>> = (loading) =
*/
const resetCurrentPassword: (
request: ResetPasswordRequest,
loading?: Ref<boolean>
loading?: Ref<boolean>,
) => Promise<Result<boolean>> = (request, loading) => {
return post('/chat_user/current/reset_password', request, undefined, loading)
}
@ -230,6 +230,21 @@ const resetCurrentPassword: (
const getChatUserProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (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<boolean>,
) => Promise<Result<any>> = (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,
}

View File

@ -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
}
/**
* 滚动条距离最上面的高度
*/