-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add systemMessage * perf: 优化代码和类型 * perf: 补全翻译和为以后做准备 --------- Co-authored-by: ChenZhaoYu <790348264@qq.com>
- Loading branch information
1 parent
e02ab1f
commit 6ecc61a
Showing
14 changed files
with
160 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ChatMessage } from 'chatgpt' | ||
|
||
export interface RequestOptions { | ||
message: string | ||
lastContext?: { conversationId?: string; parentMessageId?: string } | ||
process?: (chat: ChatMessage) => void | ||
systemMessage?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import { NButton, NInput, useMessage } from 'naive-ui' | ||
import { useSettingStore } from '@/store' | ||
import type { SettingsState } from '@/store/modules/settings/helper' | ||
import { t } from '@/locales' | ||
const settingStore = useSettingStore() | ||
const ms = useMessage() | ||
const systemMessage = ref(settingStore.systemMessage ?? '') | ||
function updateSettings(options: Partial<SettingsState>) { | ||
settingStore.updateSetting(options) | ||
ms.success(t('common.success')) | ||
} | ||
function handleReset() { | ||
settingStore.resetSetting() | ||
ms.success(t('common.success')) | ||
window.location.reload() | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="p-4 space-y-5 min-h-[200px]"> | ||
<div class="space-y-6"> | ||
<div class="flex items-center space-x-4"> | ||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.role') }}</span> | ||
<div class="flex-1"> | ||
<NInput v-model:value="systemMessage" placeholder="" /> | ||
</div> | ||
<NButton size="tiny" text type="primary" @click="updateSettings({ systemMessage })"> | ||
{{ $t('common.save') }} | ||
</NButton> | ||
</div> | ||
<div class="flex items-center space-x-4"> | ||
<span class="flex-shrink-0 w-[100px]"> </span> | ||
<NButton size="small" @click="handleReset"> | ||
{{ $t('common.reset') }} | ||
</NButton> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ss } from '@/utils/storage' | ||
|
||
const LOCAL_NAME = 'settingsStorage' | ||
|
||
export interface SettingsState { | ||
systemMessage: string | ||
} | ||
|
||
export function defaultSetting(): SettingsState { | ||
const currentDate = new Date().toISOString().split('T')[0] | ||
return { | ||
systemMessage: `You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: ${currentDate}`, | ||
} | ||
} | ||
|
||
export function getLocalState(): SettingsState { | ||
const localSetting: SettingsState | undefined = ss.get(LOCAL_NAME) | ||
return { ...defaultSetting(), ...localSetting } | ||
} | ||
|
||
export function setLocalState(setting: SettingsState): void { | ||
ss.set(LOCAL_NAME, setting) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { defineStore } from 'pinia' | ||
import type { SettingsState } from './helper' | ||
import { defaultSetting, getLocalState, setLocalState } from './helper' | ||
|
||
export const useSettingStore = defineStore('setting-store', { | ||
state: (): SettingsState => getLocalState(), | ||
actions: { | ||
updateSetting(settings: Partial<SettingsState>) { | ||
this.$state = { ...this.$state, ...settings } | ||
this.recordState() | ||
}, | ||
|
||
resetSetting() { | ||
this.$state = defaultSetting() | ||
this.recordState() | ||
}, | ||
|
||
recordState() { | ||
setLocalState(this.$state) | ||
}, | ||
}, | ||
}) |