mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-27 12:12:57 +00:00
feat: 对话增加历史记录功能
This commit is contained in:
parent
2d4723751a
commit
5de78cf446
|
|
@ -173,6 +173,18 @@ const getRecordDetail: (
|
|||
)
|
||||
}
|
||||
|
||||
const getChatLogClient: (
|
||||
application_id: String,
|
||||
page: pageRequest,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (application_id, page, loading) => {
|
||||
return get(
|
||||
`${prefix}/${application_id}/chat/client/${page.current_page}/${page.page_size}`,
|
||||
null,
|
||||
loading
|
||||
)
|
||||
}
|
||||
|
||||
export default {
|
||||
getChatLog,
|
||||
delChatLog,
|
||||
|
|
@ -181,5 +193,6 @@ export default {
|
|||
getMarkRecord,
|
||||
getRecordDetail,
|
||||
delMarkRecord,
|
||||
exportChatLog
|
||||
exportChatLog,
|
||||
getChatLogClient
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,9 +73,7 @@
|
|||
|
||||
<el-card v-else shadow="always" class="dialog-card">
|
||||
<MdRenderer :source="item.answer_text"></MdRenderer>
|
||||
<div
|
||||
v-if="(id && item.write_ed) || (props.data?.show_source && item.write_ed) || log"
|
||||
>
|
||||
<div v-if="showSource(item)">
|
||||
<el-divider> <el-text type="info">知识来源</el-text> </el-divider>
|
||||
<div class="mb-8">
|
||||
<el-space wrap>
|
||||
|
|
@ -208,8 +206,15 @@ const props = defineProps({
|
|||
available: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
chatId: {
|
||||
type: String,
|
||||
default: ''
|
||||
} // 历史记录Id
|
||||
})
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
|
||||
const { application } = useStore()
|
||||
|
||||
const ParagraphSourceDialogRef = ref()
|
||||
|
|
@ -248,6 +253,18 @@ const prologueList = computed(() => {
|
|||
return arr
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.chatId,
|
||||
(val) => {
|
||||
if (val && val !== 'new') {
|
||||
chartOpenId.value = val
|
||||
} else {
|
||||
chartOpenId.value = ''
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {
|
||||
|
|
@ -266,6 +283,18 @@ watch(
|
|||
}
|
||||
)
|
||||
|
||||
function showSource(row: any) {
|
||||
if (props.log) {
|
||||
return true
|
||||
} else if (row.write_ed) {
|
||||
if (id || props.data?.show_source) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function openParagraph(row: any, id?: string) {
|
||||
ParagraphSourceDialogRef.value.open(row, id)
|
||||
}
|
||||
|
|
@ -484,6 +513,9 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean) {
|
|||
}
|
||||
})
|
||||
.then(() => {
|
||||
if (props.chatId === 'new') {
|
||||
emit('refresh', chartOpenId.value)
|
||||
}
|
||||
return (id || props.data?.show_source) && getSourceDetail(chat)
|
||||
})
|
||||
.finally(() => {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,18 @@ const useLogStore = defineStore({
|
|||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
async asyncGetChatLogClient(id: string, page: pageRequest, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logApi
|
||||
.getChatLogClient(id, page, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -58,11 +58,8 @@ function getChatLog(id: string) {
|
|||
current_page: 1,
|
||||
page_size: 20
|
||||
}
|
||||
const param = {
|
||||
history_day: 183
|
||||
}
|
||||
|
||||
log.asyncGetChatLog(id, page, param, loading).then((res: any) => {
|
||||
log.asyncGetChatLogClient(id, page, loading).then((res: any) => {
|
||||
chatLogeData.value = res.data.records
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
:data="chatLogeData"
|
||||
class="mt-8"
|
||||
v-loading="loading"
|
||||
:defaultActive="currentId"
|
||||
:defaultActive="currentChatId"
|
||||
@click="clickListHandle"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
|
|
@ -39,6 +39,8 @@
|
|||
:available="applicationAvailable"
|
||||
:appId="applicationDetail?.id"
|
||||
:record="currentRecordList"
|
||||
:chatId="currentChatId"
|
||||
@refresh="refresh"
|
||||
></AiChat>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -69,9 +71,8 @@ const paginationConfig = reactive({
|
|||
total: 0
|
||||
})
|
||||
|
||||
const currentChatId = ref('')
|
||||
const currentRecordList = ref<any>([])
|
||||
const currentId = ref('0')
|
||||
const currentChatId = ref('0') // 当前历史记录Id 默认为'0'
|
||||
|
||||
function getAccessToken(token: string) {
|
||||
application
|
||||
|
|
@ -96,14 +97,19 @@ function getProfile() {
|
|||
}
|
||||
|
||||
function newChat() {
|
||||
paginationConfig.current_page = 1
|
||||
currentRecordList.value = []
|
||||
if (!chatLogeData.value.some((v) => v.id === 'new')) {
|
||||
paginationConfig.current_page = 1
|
||||
currentRecordList.value = []
|
||||
|
||||
chatLogeData.value.unshift({
|
||||
id: 'new',
|
||||
abstract: '新的对话'
|
||||
})
|
||||
currentId.value = 'new'
|
||||
chatLogeData.value.unshift({
|
||||
id: 'new',
|
||||
abstract: '新的对话'
|
||||
})
|
||||
} else {
|
||||
paginationConfig.current_page = 1
|
||||
currentRecordList.value = []
|
||||
}
|
||||
currentChatId.value = 'new'
|
||||
}
|
||||
|
||||
function getChatLog(id: string) {
|
||||
|
|
@ -111,11 +117,8 @@ function getChatLog(id: string) {
|
|||
current_page: 1,
|
||||
page_size: 20
|
||||
}
|
||||
const param = {
|
||||
history_day: 183
|
||||
}
|
||||
|
||||
log.asyncGetChatLog(id, page, param, loading).then((res: any) => {
|
||||
log.asyncGetChatLogClient(id, page, loading).then((res: any) => {
|
||||
chatLogeData.value = res.data.records
|
||||
})
|
||||
}
|
||||
|
|
@ -131,13 +134,18 @@ function getChatRecord() {
|
|||
const clickListHandle = (item: any) => {
|
||||
paginationConfig.current_page = 1
|
||||
currentRecordList.value = []
|
||||
currentChatId.value = item.chat_id
|
||||
currentId.value = item.id
|
||||
if (currentChatId.value) {
|
||||
currentChatId.value = item.id
|
||||
if (currentChatId.value !== 'new') {
|
||||
getChatRecord()
|
||||
}
|
||||
}
|
||||
|
||||
function refresh(id: string) {
|
||||
console.log(id)
|
||||
getChatLog(applicationDetail.value.id)
|
||||
currentChatId.value = id
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
user.changeUserType(2)
|
||||
getAccessToken(accessToken)
|
||||
|
|
|
|||
Loading…
Reference in New Issue