Skip to content

Commit a4422c2

Browse files
committed
feat: set user default chat model
Signed-off-by: BobDu <i@bobdu.cc>
1 parent 2ca06bb commit a4422c2

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

src/components/common/Setting/General.vue

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<script lang="ts" setup>
22
import { computed, ref } from 'vue'
3-
import { NButton, NInput, NPopconfirm, NSelect, useMessage } from 'naive-ui'
3+
import { NButton, NDivider, NInput, NPopconfirm, NSelect, useMessage } from 'naive-ui'
4+
import { UserConfig } from '@/components/common/Setting/model'
45
import type { Language, Theme } from '@/store/modules/app/helper'
56
import { SvgIcon } from '@/components/common'
6-
import { useAppStore, useUserStore } from '@/store'
7+
import { useAppStore, useAuthStore, useUserStore } from '@/store'
78
import type { UserInfo } from '@/store/modules/user/helper'
89
import { getCurrentDate } from '@/utils/functions'
910
import { useBasicLayout } from '@/hooks/useBasicLayout'
1011
import { t } from '@/locales'
11-
import { fetchClearAllChat } from '@/api'
12+
import { fetchClearAllChat, fetchUpdateUserChatModel } from '@/api'
1213
1314
const appStore = useAppStore()
1415
const userStore = useUserStore()
16+
const authStore = useAuthStore()
1517
1618
const { isMobile } = useBasicLayout()
1719
@@ -66,6 +68,14 @@ async function updateUserInfo(options: Partial<UserInfo>) {
6668
ms.success(t('common.success'))
6769
}
6870
71+
async function updateUserChatModel(chatModel: string) {
72+
if (!userStore.userInfo.config)
73+
userStore.userInfo.config = new UserConfig()
74+
userStore.userInfo.config.chatModel = chatModel
75+
userStore.recordState()
76+
await fetchUpdateUserChatModel(chatModel)
77+
}
78+
6979
function exportData(): void {
7080
const date = getCurrentDate()
7181
const data: string = localStorage.getItem('chatStorage') || '{}'
@@ -138,6 +148,25 @@ function handleImportButtonClick(): void {
138148
<NInput v-model:value="avatar" placeholder="" />
139149
</div>
140150
</div>
151+
<div class="flex items-center space-x-4">
152+
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.saveUserInfo') }}</span>
153+
<NButton type="primary" @click="updateUserInfo({ avatar, name, description })">
154+
{{ $t('common.save') }}
155+
</NButton>
156+
</div>
157+
<NDivider />
158+
<div class="flex items-center space-x-4">
159+
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.defaultChatModel') }}</span>
160+
<div class="w-[200px]">
161+
<NSelect
162+
style="width: 200px"
163+
:value="userInfo.config.chatModel"
164+
:options="authStore.session?.chatModels"
165+
:disabled="!!authStore.session?.auth && !authStore.token"
166+
@update-value="(val) => updateUserChatModel(val)"
167+
/>
168+
</div>
169+
</div>
141170
<div
142171
class="flex items-center space-x-4"
143172
:class="isMobile && 'items-start'"
@@ -200,12 +229,6 @@ function handleImportButtonClick(): void {
200229
/>
201230
</div>
202231
</div>
203-
<div class="flex items-center space-x-4">
204-
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.saveUserInfo') }}</span>
205-
<NButton type="primary" @click="updateUserInfo({ avatar, name, description })">
206-
{{ $t('common.save') }}
207-
</NButton>
208-
</div>
209232
</div>
210233
</div>
211234
</template>

src/locales/en-US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default {
142142
userRoles: 'User Role',
143143
status: 'Status',
144144
chatModels: 'Chat Models',
145+
defaultChatModel: 'Default Chat Model',
145146
remark: 'Remark',
146147
email: 'Email',
147148
password: 'Password',

src/locales/ko-KR.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default {
140140
userRoles: 'User Role',
141141
status: 'Status',
142142
chatModels: 'Chat Models',
143+
defaultChatModel: '기본 대화 모델',
143144
remark: 'Remark',
144145
email: 'Email',
145146
password: 'Password',

src/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default {
142142
userRoles: '用户权限',
143143
status: '状态',
144144
chatModels: '对话模型',
145+
defaultChatModel: '默认对话模型',
145146
remark: '备注',
146147
email: '电子邮箱',
147148
password: '密码',

src/locales/zh-TW.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default {
142142
userRoles: '用戶權限',
143143
status: '狀態',
144144
chatModels: '對話模型',
145+
defaultChatModel: '預設對話模型',
145146
remark: '備註',
146147
email: '電子郵箱',
147148
password: '密碼',

0 commit comments

Comments
 (0)