Skip to content

Commit

Permalink
Merge pull request #501 from sugarforever/feat/clearHistory
Browse files Browse the repository at this point in the history
支持清空会话历史
  • Loading branch information
satrong authored Jun 2, 2024
2 parents 2bb6d7f + df9e525 commit a42ba32
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions components/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ function onOpenSettings() {
instructionInfo.value = data.instructionInfo
emits('changeSettings', updatedSessionInfo)
},
onClear: () => {
messages.value = []
}
})
}
Expand Down
15 changes: 15 additions & 0 deletions components/ChatSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const props = defineProps<{
sessionId: number
onClose: () => void
onUpdated?: (data: UpdatedOptions) => void
onClear?: () => void
}>()
const { t } = useI18n()
const confirm = useDialog('confirm')
const defaultConfig = {
instructionId: 0,
Expand Down Expand Up @@ -44,6 +46,16 @@ onMounted(() => {
})
})
function onClearHistory() {
props.onClose()
nextTick(() => {
confirm(t('chat.clearConfirmTip')).then(async () => {
await clientDB.chatHistories.where('sessionId').equals(props.sessionId).delete()
props.onClear?.()
}).catch(noop)
})
}
async function onSave() {
const knowledgeBaseInfo = knowledgeBases.find(el => el.id === state.knowledgeBaseId)
const instructionInfo = instructions.find(el => el.id === state.instructionId)
Expand Down Expand Up @@ -101,6 +113,9 @@ async function onReset() {
<URange v-model="state.attachedMessagesCount" :min="0" :max="$config.public.chatMaxAttachedMessages" size="md" />
</div>
</UFormGroup>
<div class="text-center mt-6">
<UButton icon="i-material-symbols-delete-history" color="red" @click="onClearHistory">{{ t('chat.clearBtn') }}</UButton>
</div>
<template #footer>
<div class="text-right">
<UButton color="gray" class="mr-2" @click="onReset">{{ t("chat.resetToDefault") }}</UButton>
Expand Down
2 changes: 1 addition & 1 deletion composables/useDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useDialog(type: 'modal' | 'confirm' | 'alert') {
props: {
title: {
type: String,
default: 'Confirm Action',
default: t('global.confirmTitle'),
},
description: {
type: String as PropType<string | VNode>,
Expand Down
11 changes: 7 additions & 4 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
"selectInstruction": "Select an Instruction",
"resend": "Resend",
"noModelFound": "No model found",
"noModelFoundDesc": "Please download a model first."
"noModelFoundDesc": "Please download a model first.",
"clearBtn": "Clear history messages",
"clearConfirmTip": "Are you sure you want to clear all history messages for this conversation?"
},
"settings": {
"ollamaServer": "Ollama Server",
Expand Down Expand Up @@ -158,9 +160,10 @@
"userName": "User Name",
"password": "Password",
"streamError": "The browser doesn't support streaming responses.",
"confirmText": "confirm",
"cancelText": "cancel",
"confirmText": "Confirm",
"cancelText": "Cancel",
"selectModel": "Select a model",
"selectModels": "Select models"
"selectModels": "Select models",
"confirmTitle": "Confirm action"
}
}
5 changes: 4 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
"selectInstruction": "选择指令",
"resend": "重发",
"noModelFound": "没有找到模型",
"noModelFoundDesc": "请先在模型管理页面下载模型"
"noModelFoundDesc": "请先在模型管理页面下载模型",
"clearBtn": "清空历史消息",
"clearConfirmTip": "确定要清空该对话的所有历史消息吗?"
},
"settings": {
"ollamaServer": "Ollama 服务",
Expand Down Expand Up @@ -158,6 +160,7 @@
"userName": "用户名称",
"password": "密码",
"streamError": "您的浏览器不支持流式响应,请使用最新版本的浏览器。",
"confirmTitle": "确定操作",
"confirmText": "确定",
"cancelText": "取消",
"selectModel": "选择模型",
Expand Down

0 comments on commit a42ba32

Please sign in to comment.