From 36081b8051b1c04fcb34dd2de2da8819592710a5 Mon Sep 17 00:00:00 2001 From: Bob Du Date: Mon, 19 May 2025 16:32:25 +0800 Subject: [PATCH] fix: new user default model use first available models list Signed-off-by: Bob Du --- .gitignore | 2 ++ service/src/index.ts | 12 ++++-------- service/src/storage/mongo.ts | 9 ++++++++- src/components/common/Setting/General.vue | 1 - src/store/modules/auth/index.ts | 4 +--- src/store/modules/user/helper.ts | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a67150c3..afd09a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ coverage # Environment variables files /service/.env /docker-compose/nginx/html + +local/ diff --git a/service/src/index.ts b/service/src/index.ts index 1f9c7601..747e2abe 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -311,21 +311,17 @@ router.post('/session', async (req, res) => { const hasAuth = config.siteConfig.loginEnabled || config.siteConfig.authProxyEnabled const authProxyEnabled = config.siteConfig.authProxyEnabled const allowRegister = config.siteConfig.registerEnabled - if (config.apiModel !== 'ChatGPTAPI' && config.apiModel !== 'ChatGPTUnofficialProxyAPI') - config.apiModel = 'ChatGPTAPI' + config.apiModel = 'ChatGPTAPI' const userId = await getUserId(req) const chatModels: { - label + label: string key: string value: string }[] = [] const chatModelOptions = config.siteConfig.chatModels.split(',').map((model: string) => { - let label = model - if (model === 'text-davinci-002-render-sha-mobile') - label = 'gpt-3.5-mobile' return { - label, + label: model, key: model, value: model, } @@ -417,7 +413,7 @@ router.post('/session', async (req, res) => { allowRegister, model: config.apiModel, title: config.siteConfig.siteTitle, - chatModels: chatModelOptions, // if userId is null which means in nologin mode, open all model options, otherwise user can only choose gpt-3.5-turbo + chatModels: chatModelOptions, allChatModels: chatModelOptions, showWatermark: config.siteConfig?.showWatermark, userInfo, diff --git a/service/src/storage/mongo.ts b/service/src/storage/mongo.ts index 92e8e0aa..2135cd08 100644 --- a/service/src/storage/mongo.ts +++ b/service/src/storage/mongo.ts @@ -360,12 +360,19 @@ export async function createUser(email: string, password: string, roles?: UserRo userInfo.roles = roles userInfo.remark = remark + + // Initialize user configuration with default settings if (limit_switch != null) userInfo.limit_switch = limit_switch if (useAmount != null) userInfo.useAmount = useAmount else userInfo.useAmount = config?.siteConfig?.globalAmount ?? 10 + + // Use the first item from the globally available chatModel configuration as the default model for new users + userInfo.config = new UserConfig() + userInfo.config.chatModel = config?.siteConfig?.chatModels.split(',')[0] + await userCol.insertOne(userInfo) return userInfo } @@ -446,7 +453,7 @@ async function initUserInfo(userInfo: WithId) { if (userInfo.config == null) userInfo.config = new UserConfig() if (userInfo.config.chatModel == null) - userInfo.config.chatModel = 'gpt-3.5-turbo' + userInfo.config.chatModel = '' if (userInfo.roles == null || userInfo.roles.length <= 0) { userInfo.roles = [] if (process.env.ROOT_USER === userInfo.email.toLowerCase()) diff --git a/src/components/common/Setting/General.vue b/src/components/common/Setting/General.vue index 540c4b7a..2c865d7a 100644 --- a/src/components/common/Setting/General.vue +++ b/src/components/common/Setting/General.vue @@ -204,7 +204,6 @@ function handleImportButtonClick(): void { style="width: 200px" :value="userInfo.config.chatModel" :options="authStore.session?.chatModels" - :disabled="!!authStore.session?.auth && !authStore.token" @update-value="(val) => updateUserChatModel(val)" /> diff --git a/src/store/modules/auth/index.ts b/src/store/modules/auth/index.ts index b3c43e46..6beb5490 100644 --- a/src/store/modules/auth/index.ts +++ b/src/store/modules/auth/index.ts @@ -62,10 +62,8 @@ export const useAuthStore = defineStore('auth-store', { this.token = token const decoded = jwt_decode(token) as UserInfo const userStore = useUserStore() - if (decoded.config === undefined || decoded.config === null) { + if (decoded.config === undefined || decoded.config === null) decoded.config = new UserConfig() - decoded.config.chatModel = 'gpt-3.5-turbo' - } await userStore.updateUserInfo(false, { avatar: decoded.avatar, diff --git a/src/store/modules/user/helper.ts b/src/store/modules/user/helper.ts index 9af78692..dfc632f3 100644 --- a/src/store/modules/user/helper.ts +++ b/src/store/modules/user/helper.ts @@ -35,7 +35,7 @@ export function defaultSetting(): UserState { name: '', description: '', root: false, - config: { chatModel: 'gpt-3.5-turbo' }, + config: { chatModel: '' }, roles: [], advanced: { systemMessage: 'You are a large language model. Follow the user\'s instructions carefully. Respond using markdown (latex start with $).', @@ -53,7 +53,7 @@ export function getLocalState(): UserState { if (localSetting != null && localSetting.userInfo != null) { if (localSetting.userInfo.config == null) { localSetting.userInfo.config = new UserConfig() - localSetting.userInfo.config.chatModel = 'gpt-3.5-turbo' + localSetting.userInfo.config.chatModel = '' } if (!localSetting.userInfo.advanced) { localSetting.userInfo.advanced = {