Skip to content

fix: new user default model use first available models list #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ coverage
# Environment variables files
/service/.env
/docker-compose/nginx/html

local/
12 changes: 4 additions & 8 deletions service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion service/src/storage/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -446,7 +453,7 @@ async function initUserInfo(userInfo: WithId<UserInfo>) {
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())
Expand Down
1 change: 0 additions & 1 deletion src/components/common/Setting/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
/>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/store/modules/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/user/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 $).',
Expand All @@ -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 = {
Expand Down