Skip to content

Commit 955b68a

Browse files
committed
feat: Chat record details
1 parent 276378a commit 955b68a

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

apps/chat/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
path('captcha', views.CaptchaView.as_view(), name='captcha'),
1515
path('vote/chat/<str:chat_id>/chat_record/<str:chat_record_id>', views.VoteView.as_view(), name='vote'),
1616
path('historical_conversation', views.HistoricalConversationView.as_view(), name='historical_conversation'),
17+
path('historical_conversation/<str:chat_id>/record/<str:chat_record_id>',views.ChatRecordView.as_view(),name='conversation_details'),
1718
path('historical_conversation/<int:current_page>/<int:page_size>', views.HistoricalConversationView.PageView.as_view(), name='historical_conversation'),
1819
path('historical_conversation_record/<str:chat_id>', views.HistoricalConversationRecordView.as_view(), name='historical_conversation_record'),
1920
path('historical_conversation_record/<str:chat_id>/<int:current_page>/<int:page_size>', views.HistoricalConversationRecordView.PageView.as_view(), name='historical_conversation_record')

apps/chat/views/chat_record.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from rest_framework.request import Request
1212
from rest_framework.views import APIView
1313

14+
from application.serializers.application_chat_record import ChatRecordOperateSerializer
1415
from chat.api.chat_api import HistoricalConversationAPI, PageHistoricalConversationAPI, \
1516
PageHistoricalConversationRecordAPI, HistoricalConversationRecordAPI
1617
from chat.api.vote_api import VoteAPI
@@ -118,3 +119,25 @@ def get(self, request: Request, chat_id: str, current_page: int, page_size: int)
118119
'application_id': request.auth.application_id,
119120
'chat_user_id': request.auth.chat_user_id,
120121
}).page(current_page, page_size))
122+
123+
124+
class ChatRecordView(APIView):
125+
authentication_classes = [TokenAuth]
126+
127+
@extend_schema(
128+
methods=['GET'],
129+
description=_("Get conversation details"),
130+
summary=_("Get conversation details"),
131+
operation_id=_("Get conversation details"), # type: ignore
132+
parameters=PageHistoricalConversationRecordAPI.get_parameters(),
133+
responses=PageHistoricalConversationRecordAPI.get_response(),
134+
tags=[_('Chat')] # type: ignore
135+
)
136+
def get(self, request: Request, chat_id: str, chat_record_id: str):
137+
return result.success(ChatRecordOperateSerializer(
138+
data={
139+
'chat_id': chat_id,
140+
'chat_record_id': chat_record_id,
141+
'application_id': request.auth.application_id,
142+
'chat_user_id': request.auth.chat_user_id,
143+
}).one(True))

ui/src/api/chat/chat.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@/request/chat/index'
1212
import { type ChatProfile } from '@/api/type/chat'
1313
import { type Ref } from 'vue'
14-
import type { ResetPasswordRequest } from "@/api/type/user.ts";
14+
import type { ResetPasswordRequest } from '@/api/type/user.ts'
1515

1616
import useStore from '@/stores'
1717
import type { LoginRequest } from '@/api/type/user'
@@ -219,7 +219,7 @@ const logout: (loading?: Ref<boolean>) => Promise<Result<boolean>> = (loading) =
219219
*/
220220
const resetCurrentPassword: (
221221
request: ResetPasswordRequest,
222-
loading?: Ref<boolean>
222+
loading?: Ref<boolean>,
223223
) => Promise<Result<boolean>> = (request, loading) => {
224224
return post('/chat_user/current/reset_password', request, undefined, loading)
225225
}
@@ -230,6 +230,21 @@ const resetCurrentPassword: (
230230
const getChatUserProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
231231
return get('/chat_user/profile', {}, loading)
232232
}
233+
/**
234+
* 获取对话详情
235+
* @param chat_id 对话id
236+
* @param chat_record_id 对话记录id
237+
* @param loading 加载器
238+
* @returns
239+
*/
240+
const getChatRecord: (
241+
chat_id: string,
242+
chat_record_id: string,
243+
loading?: Ref<boolean>,
244+
) => Promise<Result<any>> = (chat_id, chat_record_id, loading) => {
245+
return get(`historical_conversation/${chat_id}/record/${chat_record_id}`, {}, loading)
246+
}
247+
233248
export default {
234249
open,
235250
chat,
@@ -252,5 +267,6 @@ export default {
252267
pageChatRecord,
253268
logout,
254269
resetCurrentPassword,
255-
getChatUserProfile
270+
getChatUserProfile,
271+
getChatRecord,
256272
}

ui/src/components/ai-chat/index.vue

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,37 @@ const getOpenChatAPI = () => {
312312
}
313313
}
314314
}
315+
316+
/**
317+
* 获取对话详情
318+
* @param row
319+
*/
320+
function getSourceDetail(row: any) {
321+
if (row.record_id) {
322+
if (props.type === 'debug-ai-chat') {
323+
chatLogApi
324+
.getChatRecordDetails(id || props.appId, row.chat_id, row.record_id, loading)
325+
.then((res) => {
326+
const exclude_keys = ['answer_text', 'id', 'answer_text_list']
327+
Object.keys(res.data).forEach((key) => {
328+
if (!exclude_keys.includes(key)) {
329+
row[key] = res.data[key]
330+
}
331+
})
332+
})
333+
} else {
334+
chatAPI.getChatRecord(row.chat_id, row.record_id, loading).then((res) => {
335+
const exclude_keys = ['answer_text', 'id', 'answer_text_list']
336+
Object.keys(res.data).forEach((key) => {
337+
if (!exclude_keys.includes(key)) {
338+
row[key] = res.data[key]
339+
}
340+
})
341+
})
342+
}
343+
}
344+
return true
345+
}
315346
/**
316347
* 对话
317348
*/
@@ -511,26 +542,6 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean, other_para
511542
}
512543
}
513544
514-
/**
515-
* 获取对话详情
516-
* @param row
517-
*/
518-
function getSourceDetail(row: any) {
519-
if (row.record_id) {
520-
chatLogApi
521-
.getChatRecordDetails(id || props.appId, row.chat_id, row.record_id, loading)
522-
.then((res) => {
523-
const exclude_keys = ['answer_text', 'id', 'answer_text_list']
524-
Object.keys(res.data).forEach((key) => {
525-
if (!exclude_keys.includes(key)) {
526-
row[key] = res.data[key]
527-
}
528-
})
529-
})
530-
}
531-
return true
532-
}
533-
534545
/**
535546
* 滚动条距离最上面的高度
536547
*/

0 commit comments

Comments
 (0)