Skip to content

Commit b50db41

Browse files
feat: History record supports modifying chat abstract
1 parent 752e1eb commit b50db41

File tree

7 files changed

+154
-12
lines changed

7 files changed

+154
-12
lines changed

ui/src/api/log.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,29 @@ const delChatClientLog: (
220220
return del(`${prefix}/${application_id}/chat/client/${chat_id}`, undefined, {}, loading)
221221
}
222222

223+
/**
224+
* 修改历史日志abstract
225+
* @param 参数
226+
* application_id, chat_id,
227+
* data {
228+
"abstract": "string",
229+
}
230+
*/
231+
232+
const putChatClientLog: (
233+
application_id: string,
234+
chat_id: string,
235+
data: any,
236+
loading?: Ref<boolean>
237+
) => Promise<Result<boolean>> = (application_id, chat_id, data, loading) => {
238+
return put(
239+
`${prefix}/${application_id}/chat/client/${chat_id}`,
240+
data,
241+
undefined,
242+
loading
243+
)
244+
}
245+
223246
export default {
224247
getChatLog,
225248
delChatLog,
@@ -231,5 +254,6 @@ export default {
231254
exportChatLog,
232255
getChatLogClient,
233256
delChatClientLog,
234-
postChatRecordLog
257+
postChatRecordLog,
258+
putChatClientLog
235259
}

ui/src/locales/lang/en-US/ai-chat.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ export default {
9090
title: 'Knowledge Quote',
9191
question: 'User Question',
9292
optimizationQuestion: 'Optimized Question'
93-
}
93+
},
94+
editTitle: 'Edit Title',
9495
}

ui/src/locales/lang/zh-CN/ai-chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default {
2525
continue: '继续',
2626
stopChat: '停止回答'
2727
},
28-
2928
tip: {
3029
error500Message: '抱歉,当前正在维护,无法提供服务,请稍后再试!',
3130
errorIdentifyMessage: '无法识别用户身份',
@@ -91,5 +90,6 @@ export default {
9190
title: '知识库引用',
9291
question: '用户问题',
9392
optimizationQuestion: '优化后问题'
94-
}
93+
},
94+
editTitle: '编辑标题',
9595
}

ui/src/locales/lang/zh-Hant/ai-chat.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ export default {
9090
title: '知識庫引用',
9191
question: '用戶問題',
9292
optimizationQuestion: '優化後問題'
93-
}
93+
},
94+
editTitle: '編輯標題',
9495
}

ui/src/stores/modules/log.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ const useLogStore = defineStore({
6060
reject(error)
6161
})
6262
})
63+
},
64+
async asyncPutChatClientLog(id: string, chatId: string, data: any, loading?: Ref<boolean>) {
65+
return new Promise((resolve, reject) => {
66+
logApi
67+
.putChatClientLog(id, chatId, data, loading)
68+
.then((data) => {
69+
resolve(data)
70+
})
71+
.catch((error) => {
72+
reject(error)
73+
})
74+
})
6375
}
6476
}
6577
})
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<template>
2+
<el-dialog
3+
:title="$t('chat.editTitle')"
4+
v-model="dialogVisible"
5+
:close-on-click-modal="false"
6+
:close-on-press-escape="false"
7+
:destroy-on-close="true"
8+
append-to-body
9+
>
10+
<el-form
11+
label-position="top"
12+
ref="fieldFormRef"
13+
:model="form"
14+
require-asterisk-position="right"
15+
>
16+
<el-form-item
17+
prop="abstract"
18+
:rules="[
19+
{
20+
required: true,
21+
message: $t('common.inputPlaceholder'),
22+
trigger: 'blur'
23+
}
24+
]"
25+
>
26+
<el-input
27+
v-model="form.abstract"
28+
maxlength="1024"
29+
show-word-limit
30+
@blur="form.abstract = form.abstract.trim()"
31+
/>
32+
</el-form-item>
33+
</el-form>
34+
<template #footer>
35+
<span class="dialog-footer">
36+
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
37+
<el-button type="primary" @click="submit(fieldFormRef)" :loading="loading">
38+
{{ $t('common.save') }}
39+
</el-button>
40+
</span>
41+
</template>
42+
</el-dialog>
43+
</template>
44+
<script setup lang="ts">
45+
import { reactive, ref, watch } from 'vue'
46+
import type { FormInstance } from 'element-plus'
47+
import useStore from '@/stores'
48+
import { t } from '@/locales'
49+
50+
const { log } = useStore()
51+
const emit = defineEmits(['refresh'])
52+
53+
const fieldFormRef = ref()
54+
const loading = ref<boolean>(false)
55+
const applicationId = ref<string>('')
56+
const chatId = ref<string>('')
57+
58+
const form = ref<any>({
59+
abstract: ''
60+
})
61+
62+
const dialogVisible = ref<boolean>(false)
63+
64+
const open = (row: any, id: string) => {
65+
applicationId.value = id
66+
chatId.value = row.id
67+
form.value.abstract = row.abstract
68+
dialogVisible.value = true
69+
}
70+
71+
const submit = async (formEl: FormInstance | undefined) => {
72+
if (!formEl) return
73+
await formEl.validate((valid) => {
74+
if (valid) {
75+
log.asyncPutChatClientLog(applicationId.value, chatId.value, form.value, loading).then(() => {
76+
emit('refresh')
77+
dialogVisible.value = false
78+
})
79+
}
80+
})
81+
}
82+
83+
defineExpose({ open, close })
84+
</script>
85+
<style lang="scss" scoped></style>

ui/src/views/chat/pc/index.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,22 @@
6666
<auto-tooltip :content="row.abstract">
6767
{{ row.abstract }}
6868
</auto-tooltip>
69-
<div @click.stop v-if="mouseId === row.id && row.id !== 'new'">
70-
<el-button style="padding: 0" link @click.stop="deleteLog(row)">
71-
<el-icon><Delete /></el-icon>
72-
</el-button>
69+
<div @click.stop v-show="mouseId === row.id && row.id !== 'new'">
70+
<el-dropdown trigger="click" :teleported="false">
71+
<el-icon class="rotate-90 mt-4"><MoreFilled /></el-icon>
72+
<template #dropdown>
73+
<el-dropdown-menu>
74+
<el-dropdown-item @click.stop="editLogTitle(row)">
75+
<el-icon><EditPen /></el-icon>
76+
{{ $t('common.edit') }}
77+
</el-dropdown-item>
78+
<el-dropdown-item @click.stop="deleteLog(row)">
79+
<el-icon><Delete /></el-icon>
80+
{{ $t('common.delete') }}
81+
</el-dropdown-item>
82+
</el-dropdown-menu>
83+
</template>
84+
</el-dropdown>
7385
</div>
7486
</div>
7587
</template>
@@ -145,6 +157,7 @@
145157
</div>
146158
</div>
147159
</div>
160+
<EditTitleDialog ref="EditTitleDialogRef" @refresh="refreshFieldTitle" />
148161
</template>
149162

150163
<script setup lang="ts">
@@ -155,14 +168,13 @@ import { isAppIcon } from '@/utils/application'
155168
import useStore from '@/stores'
156169
import useResize from '@/layout/hooks/useResize'
157170
import { hexToRgba } from '@/utils/theme'
171+
import EditTitleDialog from './EditTitleDialog.vue'
158172
import { t } from '@/locales'
159173
useResize()
160174
161175
const { user, log, common } = useStore()
162176
163-
const isDefaultTheme = computed(() => {
164-
return user.isDefaultTheme()
165-
})
177+
const EditTitleDialogRef = ref()
166178
167179
const isCollapse = ref(false)
168180
@@ -216,6 +228,13 @@ const mouseId = ref('')
216228
function mouseenter(row: any) {
217229
mouseId.value = row.id
218230
}
231+
232+
function editLogTitle(row: any) {
233+
EditTitleDialogRef.value.open(row, applicationDetail.value.id)
234+
}
235+
function refreshFieldTitle() {
236+
getChatLog(applicationDetail.value.id)
237+
}
219238
function deleteLog(row: any) {
220239
log.asyncDelChatClientLog(applicationDetail.value.id, row.id, left_loading).then(() => {
221240
if (currentChatId.value === row.id) {

0 commit comments

Comments
 (0)