diff --git a/src/database/core/db.ts b/src/database/core/db.ts index dd2909e172e0..cc724da26f13 100644 --- a/src/database/core/db.ts +++ b/src/database/core/db.ts @@ -148,7 +148,9 @@ export class LocalDB extends Dexie { upgradeToV8 = async (trans: Transaction) => { const users = trans.table('users'); users.toCollection().modify((user: DB_User) => { - user.settings = MigrationLLMSettings.migrateSettings(user.settings as any); + if (user.settings) { + user.settings = MigrationLLMSettings.migrateSettings(user.settings as any); + } }); }; } diff --git a/src/migrations/FromV3ToV4/index.ts b/src/migrations/FromV3ToV4/index.ts index 3b0efbc68004..e86cfe9a9cd6 100644 --- a/src/migrations/FromV3ToV4/index.ts +++ b/src/migrations/FromV3ToV4/index.ts @@ -22,6 +22,9 @@ export class MigrationV3ToV4 implements Migration { static migrateSettings = (settings: V3Settings): V4Settings => { const { languageModel } = settings; + + if (!languageModel) return { ...settings, languageModel: undefined }; + const { openAI, togetherai, openrouter, ollama, ...res } = languageModel; const { openai, azure } = this.migrateOpenAI(openAI); diff --git a/src/migrations/FromV3ToV4/types/v4.ts b/src/migrations/FromV3ToV4/types/v4.ts index 87f9fbc8a59c..c4ee29ac8786 100644 --- a/src/migrations/FromV3ToV4/types/v4.ts +++ b/src/migrations/FromV3ToV4/types/v4.ts @@ -29,7 +29,7 @@ export interface V4lLLMConfig * 配置设置 */ export interface V4Settings extends Omit { - languageModel: V4lLLMConfig; + languageModel?: V4lLLMConfig; } export interface V4ConfigState { diff --git a/src/store/global/slices/settings/selectors/modelProvider.ts b/src/store/global/slices/settings/selectors/modelProvider.ts index c65f98c2c7b9..e54c085346f7 100644 --- a/src/store/global/slices/settings/selectors/modelProvider.ts +++ b/src/store/global/slices/settings/selectors/modelProvider.ts @@ -20,6 +20,7 @@ import { ServerModelProviderConfig } from '@/types/serverConfig'; import { GlobalLLMProviderKey } from '@/types/settings'; import { GlobalStore } from '../../../store'; +import { currentSettings } from './settings'; /** * get the server side model cards @@ -39,7 +40,7 @@ const serverProviderModelCards = const remoteProviderModelCards = (provider: GlobalLLMProviderKey) => (s: GlobalStore): ChatModelCard[] | undefined => { - const cards = s.settings.languageModel?.[provider]?.remoteModelCards as + const cards = currentSettings(s).languageModel?.[provider]?.remoteModelCards as | ChatModelCard[] | undefined;