Skip to content

Commit e64d52d

Browse files
authored
fix: new user default model use first available models list (#605)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent 5081879 commit e64d52d

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ coverage
3131
# Environment variables files
3232
/service/.env
3333
/docker-compose/nginx/html
34+
35+
local/

service/src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,17 @@ router.post('/session', async (req, res) => {
311311
const hasAuth = config.siteConfig.loginEnabled || config.siteConfig.authProxyEnabled
312312
const authProxyEnabled = config.siteConfig.authProxyEnabled
313313
const allowRegister = config.siteConfig.registerEnabled
314-
if (config.apiModel !== 'ChatGPTAPI' && config.apiModel !== 'ChatGPTUnofficialProxyAPI')
315-
config.apiModel = 'ChatGPTAPI'
314+
config.apiModel = 'ChatGPTAPI'
316315
const userId = await getUserId(req)
317316
const chatModels: {
318-
label
317+
label: string
319318
key: string
320319
value: string
321320
}[] = []
322321

323322
const chatModelOptions = config.siteConfig.chatModels.split(',').map((model: string) => {
324-
let label = model
325-
if (model === 'text-davinci-002-render-sha-mobile')
326-
label = 'gpt-3.5-mobile'
327323
return {
328-
label,
324+
label: model,
329325
key: model,
330326
value: model,
331327
}
@@ -417,7 +413,7 @@ router.post('/session', async (req, res) => {
417413
allowRegister,
418414
model: config.apiModel,
419415
title: config.siteConfig.siteTitle,
420-
chatModels: chatModelOptions, // if userId is null which means in nologin mode, open all model options, otherwise user can only choose gpt-3.5-turbo
416+
chatModels: chatModelOptions,
421417
allChatModels: chatModelOptions,
422418
showWatermark: config.siteConfig?.showWatermark,
423419
userInfo,

service/src/storage/mongo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,19 @@ export async function createUser(email: string, password: string, roles?: UserRo
360360

361361
userInfo.roles = roles
362362
userInfo.remark = remark
363+
364+
// Initialize user configuration with default settings
363365
if (limit_switch != null)
364366
userInfo.limit_switch = limit_switch
365367
if (useAmount != null)
366368
userInfo.useAmount = useAmount
367369
else
368370
userInfo.useAmount = config?.siteConfig?.globalAmount ?? 10
371+
372+
// Use the first item from the globally available chatModel configuration as the default model for new users
373+
userInfo.config = new UserConfig()
374+
userInfo.config.chatModel = config?.siteConfig?.chatModels.split(',')[0]
375+
369376
await userCol.insertOne(userInfo)
370377
return userInfo
371378
}
@@ -446,7 +453,7 @@ async function initUserInfo(userInfo: WithId<UserInfo>) {
446453
if (userInfo.config == null)
447454
userInfo.config = new UserConfig()
448455
if (userInfo.config.chatModel == null)
449-
userInfo.config.chatModel = 'gpt-3.5-turbo'
456+
userInfo.config.chatModel = ''
450457
if (userInfo.roles == null || userInfo.roles.length <= 0) {
451458
userInfo.roles = []
452459
if (process.env.ROOT_USER === userInfo.email.toLowerCase())

src/components/common/Setting/General.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ function handleImportButtonClick(): void {
204204
style="width: 200px"
205205
:value="userInfo.config.chatModel"
206206
:options="authStore.session?.chatModels"
207-
:disabled="!!authStore.session?.auth && !authStore.token"
208207
@update-value="(val) => updateUserChatModel(val)"
209208
/>
210209
</div>

src/store/modules/auth/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ export const useAuthStore = defineStore('auth-store', {
6262
this.token = token
6363
const decoded = jwt_decode(token) as UserInfo
6464
const userStore = useUserStore()
65-
if (decoded.config === undefined || decoded.config === null) {
65+
if (decoded.config === undefined || decoded.config === null)
6666
decoded.config = new UserConfig()
67-
decoded.config.chatModel = 'gpt-3.5-turbo'
68-
}
6967

7068
await userStore.updateUserInfo(false, {
7169
avatar: decoded.avatar,

src/store/modules/user/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function defaultSetting(): UserState {
3535
name: '',
3636
description: '',
3737
root: false,
38-
config: { chatModel: 'gpt-3.5-turbo' },
38+
config: { chatModel: '' },
3939
roles: [],
4040
advanced: {
4141
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 {
5353
if (localSetting != null && localSetting.userInfo != null) {
5454
if (localSetting.userInfo.config == null) {
5555
localSetting.userInfo.config = new UserConfig()
56-
localSetting.userInfo.config.chatModel = 'gpt-3.5-turbo'
56+
localSetting.userInfo.config.chatModel = ''
5757
}
5858
if (!localSetting.userInfo.advanced) {
5959
localSetting.userInfo.advanced = {

0 commit comments

Comments
 (0)