feat: 添加角色设定预留API 设定页(#768)
* add systemMessage * perf: 优化代码和类型 * perf: 补全翻译和为以后做准备 --------- Co-authored-by: ChenZhaoYu <790348264@qq.com>main
parent
e02ab1fbad
commit
6ecc61ac5d
@ -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
|
||||||
|
}
|
@ -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>
|
@ -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)
|
||||||
|
}
|
@ -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)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
Loading…
Reference in New Issue