Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加了一个可以是否要发送历史上下文的开关 #393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ For all parameter variables, check [here](#docker-parameter-example) or see:

[✓] Formatting and beautifying code-like message types

[✓] Access rights control

[✓] Data import and export

[✓] Save message to local image

[✓] Multilingual interface

[✓] Interface themes
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ API_REVERSE_PROXY=

[✓] 对代码等消息类型的格式化美化处理

[✓] 访问权限控制

[✓] 数据导入、导出

[✓] 保存消息到本地图片

[✓] 界面多语言

[✓] 界面主题
Expand Down
64 changes: 34 additions & 30 deletions src/components/common/Setting/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const themeOptions: { label: string; key: Theme; icon: string }[] = [
]

const languageOptions: { label: string; key: Language; value: Language }[] = [
{ label: '中文', key: 'zh-CN', value: 'zh-CN' },
{ label: '简体中文', key: 'zh-CN', value: 'zh-CN' },
{ label: '繁體中文', key: 'zh-TW', value: 'zh-TW' },
{ label: 'English', key: 'en-US', value: 'en-US' },
]
Expand Down Expand Up @@ -151,38 +151,41 @@ function handleImportButtonClick(): void {
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatHistory') }}</span>

<NButton @click="exportData">
<template #icon>
<SvgIcon icon="ri:download-2-fill" />
</template>
{{ $t('common.export') }}
</NButton>

<input id="fileInput" type="file" style="display:none" @change="importData">
<NButton @click="handleImportButtonClick">
<template #icon>
<SvgIcon icon="ri:upload-2-fill" />
</template>
{{ $t('common.import') }}
</NButton>

<NPopconfirm placement="bottom" @positive-click="clearData">
<template #trigger>
<NButton>
<template #icon>
<SvgIcon icon="ri:close-circle-line" />
</template>
{{ $t('common.clear') }}
</NButton>
</template>
{{ $t('chat.clearHistoryConfirm') }}
</NPopconfirm>
<div class="flex flex-wrap items-center gap-4">
<NButton size="small" @click="exportData">
<template #icon>
<SvgIcon icon="ri:download-2-fill" />
</template>
{{ $t('common.export') }}
</NButton>

<input id="fileInput" type="file" style="display:none" @change="importData">
<NButton size="small" @click="handleImportButtonClick">
<template #icon>
<SvgIcon icon="ri:upload-2-fill" />
</template>
{{ $t('common.import') }}
</NButton>

<NPopconfirm placement="bottom" @positive-click="clearData">
<template #trigger>
<NButton size="small">
<template #icon>
<SvgIcon icon="ri:close-circle-line" />
</template>
{{ $t('common.clear') }}
</NButton>
</template>
{{ $t('chat.clearHistoryConfirm') }}
</NPopconfirm>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
<div class="flex items-center space-x-4">
<div class="flex flex-wrap items-center gap-4">
<template v-for="item of themeOptions" :key="item.key">
<NButton
size="small"
:type="item.key === theme ? 'primary' : undefined"
@click="appStore.setTheme(item.key)"
>
Expand All @@ -195,9 +198,10 @@ function handleImportButtonClick(): void {
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
<div class="flex items-center space-x-4">
<div class="flex flex-wrap items-center gap-4">
<template v-for="item of languageOptions" :key="item.key">
<NButton
size="small"
:type="item.key === language ? 'primary' : undefined"
@click="appStore.setLanguage(item.key)"
>
Expand All @@ -208,7 +212,7 @@ function handleImportButtonClick(): void {
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
<NButton @click="handleReset">
<NButton size="small" @click="handleReset">
{{ $t('common.reset') }}
</NButton>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const show = computed({

<template>
<NModal v-model:show="show" :auto-focus="false">
<NCard role="dialog" aria-modal="true" :bordered="false" style="width: 100%; max-width: 640px">
<NCard role="dialog" aria-modal="true" :bordered="false" style="width: 95%; max-width: 640px">
<NTabs v-model:value="active" type="line" animated>
<NTabPane name="General" tab="General">
<template #tab>
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default {
exportImageConfirm: 'Are you sure to export this chat to png?',
exportSuccess: 'Export Success',
exportFailed: 'Export Failed',
usingContext: 'Context Mode',
turnOnContext: 'In the current mode, sending messages will carry previous chat records.',
turnOffContext: 'In the current mode, sending messages will not carry previous chat records.',
deleteMessage: 'Delete Message',
deleteMessageConfirm: 'Are you sure to delete this message?',
deleteHistoryConfirm: 'Are you sure to clear this history?',
Expand Down
5 changes: 4 additions & 1 deletion src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
unauthorizedTips: '未经授权,请先进行验证。',
},
chat: {
placeholder: '来说点什么...(Shift + Enter = 换行)',
placeholder: '来说点什么吧...(Shift + Enter = 换行)',
placeholderMobile: '来说点什么...',
copy: '复制',
copied: '复制成功',
Expand All @@ -27,6 +27,9 @@ export default {
exportImageConfirm: '是否将会话保存为图片?',
exportSuccess: '保存成功',
exportFailed: '保存失败',
usingContext: '上下文模式',
turnOnContext: '当前模式下, 发送消息会携带之前的聊天记录',
turnOffContext: '当前模式下, 发送消息不会携带之前的聊天记录',
deleteMessage: '删除消息',
deleteMessageConfirm: '是否删除此消息?',
deleteHistoryConfirm: '确定删除此记录?',
Expand Down
16 changes: 10 additions & 6 deletions src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export default {
delete: '刪除',
save: '儲存',
reset: '重設',
export: '導出',
import: '導入',
clear: '清空',
export: '匯出',
import: '匯入',
clear: '清除',
yes: '是',
no: '否',
noData: '暫無資料',
Expand All @@ -16,17 +16,20 @@ export default {
unauthorizedTips: '未經授權,請先進行驗證。',
},
chat: {
placeholder: '來講點什麼...(Shift + Enter = 換行)',
placeholderMobile: '來講點什麼...',
placeholder: '來說點什麼...(Shift + Enter = 換行)',
placeholderMobile: '來說點什麼...',
copy: '複製',
copied: '複製成功',
copyCode: '複製代碼',
clearChat: '清空對話',
clearChat: '清除對話',
clearChatConfirm: '是否清空對話?',
exportImage: '儲存對話為圖片',
exportImageConfirm: '是否將對話儲存為圖片?',
exportSuccess: '儲存成功',
exportFailed: '儲存失敗',
usingContext: '上下文模式',
turnOnContext: '在當前模式下, 發送訊息會攜帶之前的聊天記錄。',
turnOffContext: '在當前模式下, 發送訊息不會攜帶之前的聊天記錄。',
deleteMessage: '刪除訊息',
deleteMessageConfirm: '是否刪除此訊息?',
deleteHistoryConfirm: '確定刪除此紀錄?',
Expand All @@ -39,6 +42,7 @@ export default {
name: '名稱',
description: '描述',
resetUserInfo: '重設使用者資訊',
chatHistory: '紀錄',
theme: '主題',
language: '語言',
api: 'API',
Expand Down
27 changes: 26 additions & 1 deletion src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.

const prompt = ref<string>('')
const loading = ref<boolean>(false)
const usingContext = ref<boolean>(true)

function handleSubmit() {
onConversation()
Expand Down Expand Up @@ -68,7 +69,7 @@ async function onConversation() {
let options: Chat.ConversationRequest = {}
const lastContext = conversationList.value[conversationList.value.length - 1]?.conversationOptions

if (lastContext)
if (lastContext && usingContext.value)
options = { ...lastContext }

addChat(
Expand Down Expand Up @@ -113,6 +114,7 @@ async function onConversation() {
requestOptions: { prompt: message, options: { ...options } },
},
)
scrollToBottom()
}
catch (error) {
//
Expand Down Expand Up @@ -362,6 +364,24 @@ function handleStop() {
}
}

function toggleUsingContext() {
usingContext.value = !usingContext.value
if (usingContext.value) {
dialog.info({
title: t('chat.usingContext'),
content: t('chat.turnOnContext'),
positiveText: t('common.yes'),
})
}
else {
dialog.info({
title: t('chat.usingContext'),
content: t('chat.turnOffContext'),
positiveText: t('common.yes'),
})
}
}

const placeholder = computed(() => {
if (isMobile.value)
return t('chat.placeholderMobile')
Expand Down Expand Up @@ -449,6 +469,11 @@ onUnmounted(() => {
<SvgIcon icon="ri:download-2-line" />
</span>
</HoverButton>
<HoverButton @click="toggleUsingContext">
<span class="text-xl" :class="{ 'text-[#4b9e5f]': usingContext, 'text-[#a8071a]': !usingContext }">
<SvgIcon icon="ri:chat-history-line" />
</span>
</HoverButton>
<NInput
v-model:value="prompt"
type="textarea"
Expand Down