Skip to content

Commit

Permalink
🐛 fix: fix db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 10, 2024
1 parent 56032e6 commit 571b6dd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/database/core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/migrations/FromV3ToV4/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/migrations/FromV3ToV4/types/v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface V4lLLMConfig
* 配置设置
*/
export interface V4Settings extends Omit<V3Settings, 'languageModel'> {
languageModel: V4lLLMConfig;
languageModel?: V4lLLMConfig;
}

export interface V4ConfigState {
Expand Down
3 changes: 2 additions & 1 deletion src/store/global/slices/settings/selectors/modelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit 571b6dd

Please sign in to comment.