Skip to content

Commit

Permalink
Fix bugs in model settings migration
Browse files Browse the repository at this point in the history
  • Loading branch information
taichimaeda committed Apr 21, 2024
1 parent 57646dc commit c66aa52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/settings/migrators/1.1.0-1.2.0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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: {
Expand Down
18 changes: 10 additions & 8 deletions src/settings/migrators/1.1.0-1.2.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c66aa52

Please sign in to comment.