From c66aa5260f6dd81e1376339bfe735fc2bb48d24f Mon Sep 17 00:00:00 2001 From: Taichi Maeda Date: Sun, 21 Apr 2024 23:51:35 +0900 Subject: [PATCH] Fix bugs in model settings migration --- src/settings/migrators/1.1.0-1.2.0.test.ts | 9 ++++++--- src/settings/migrators/1.1.0-1.2.0.ts | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/settings/migrators/1.1.0-1.2.0.test.ts b/src/settings/migrators/1.1.0-1.2.0.test.ts index 196d2a7..8ca41f0 100644 --- a/src/settings/migrators/1.1.0-1.2.0.test.ts +++ b/src/settings/migrators/1.1.0-1.2.0.test.ts @@ -19,7 +19,7 @@ const version1_1_0: MarkpilotSettings1_1_0 = { }, chat: { enabled: true, - model: 'gpt-3.5-turbo', + model: 'gpt-4', maxTokens: 10, temperature: 0.1, history: { @@ -43,6 +43,9 @@ const version1_1_0: MarkpilotSettings1_1_0 = { const version1_2_0: MarkpilotSettings1_2_0 = { version: '1.2.0', + backups: { + '1.1.0': structuredClone(version1_1_0), + }, providers: { openai: { apiKey: 'test', @@ -58,7 +61,7 @@ const version1_2_0: MarkpilotSettings1_2_0 = { enabled: true, provider: 'openai', model: 'gpt-3.5-turbo', - fewShot: true, + fewShot: false, maxTokens: 10, temperature: 0.5, waitTime: 10, @@ -71,7 +74,7 @@ const version1_2_0: MarkpilotSettings1_2_0 = { chat: { enabled: true, provider: 'openai', - model: 'gpt-3.5-turbo', + model: 'gpt-4', maxTokens: 10, temperature: 1, history: { diff --git a/src/settings/migrators/1.1.0-1.2.0.ts b/src/settings/migrators/1.1.0-1.2.0.ts index a9ed12a..6cb6daa 100644 --- a/src/settings/migrators/1.1.0-1.2.0.ts +++ b/src/settings/migrators/1.1.0-1.2.0.ts @@ -48,14 +48,16 @@ export const migrateVersion1_1_0_toVersion1_2_0: SettingsMigrator< // Update if OpenAI models selected by the user are no longer available. // Version 1.1.0 only supported OpenAI but included models // that are aliased, deprecated or only preview models. - newSettings.completions.model = - settings.completions.model in OPENAI_MODELS - ? (settings.completions.model as OpenAIModel) - : 'gpt-3.5-turbo'; - newSettings.chat.model = - settings.chat.model in OPENAI_MODELS - ? (settings.chat.model as OpenAIModel) - : 'gpt-3.5-turbo'; + if ((OPENAI_MODELS as string[]).includes(settings.completions.model)) { + newSettings.completions.model = settings.completions.model as OpenAIModel; + } else { + newSettings.completions.model = 'gpt-3.5-turbo'; + } + if ((OPENAI_MODELS as string[]).includes(settings.chat.model)) { + newSettings.chat.model = settings.chat.model as OpenAIModel; + } else { + newSettings.chat.model = 'gpt-3.5-turbo'; + } // Update if default temperature is still selected. if (settings.chat.temperature === 0.1) { newSettings.chat.temperature = 1;