Adjust reasoning template migration procedure
| @@ -55,7 +55,7 @@ import { POPUP_TYPE, callGenericPopup } from './popup.js'; | |||
| 55 | import { loadSystemPrompts } from './sysprompt.js'; | 55 | import { loadSystemPrompts } from './sysprompt.js'; |
| 56 | import { fuzzySearchCategories } from './filters.js'; | 56 | import { fuzzySearchCategories } from './filters.js'; |
| 57 | import { accountStorage } from './util/AccountStorage.js'; | 57 | import { accountStorage } from './util/AccountStorage.js'; |
| 58 | import { loadReasoningTemplates } from './reasoning.js'; | 58 | import { DEFAULT_REASONING_TEMPLATE, loadReasoningTemplates } from './reasoning.js'; |
| 59 | 59 | ||
| 60 | export { | 60 | export { |
| 61 | loadPowerUserSettings, | 61 | loadPowerUserSettings, |
| @@ -258,7 +258,7 @@ let power_user = { | |||
| 258 | }, | 258 | }, |
| 259 | 259 | ||
| 260 | reasoning: { | 260 | reasoning: { |
| 261 | name: 'DeepSeek', | 261 | name: DEFAULT_REASONING_TEMPLATE, |
| 262 | auto_parse: false, | 262 | auto_parse: false, |
| 263 | add_to_prompts: false, | 263 | add_to_prompts: false, |
| 264 | auto_expand: false, | 264 | auto_expand: false, |
| @@ -8,6 +8,7 @@ import { MacrosParser } from './macros.js'; | |||
| 8 | import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js'; | 8 | import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js'; |
| 9 | import { Popup } from './popup.js'; | 9 | import { Popup } from './popup.js'; |
| 10 | import { performFuzzySearch, power_user } from './power-user.js'; | 10 | import { performFuzzySearch, power_user } from './power-user.js'; |
| 11 | import { getPresetManager } from './preset-manager.js'; | ||
| 11 | import { SlashCommand } from './slash-commands/SlashCommand.js'; | 12 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| 12 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; | 13 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; |
| 13 | import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; | 14 | import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| @@ -29,6 +30,8 @@ import { copyText, escapeRegex, isFalseBoolean, isTrueBoolean, setDatasetPropert | |||
| 29 | */ | 30 | */ |
| 30 | export const reasoning_templates = []; | 31 | export const reasoning_templates = []; |
| 31 | 32 | ||
| 33 | export const DEFAULT_REASONING_TEMPLATE = 'DeepSeek'; | ||
| 34 | |||
| 32 | /** | 35 | /** |
| 33 | * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings | 36 | * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings |
| 34 | * @readonly | 37 | * @readonly |
| @@ -1337,8 +1340,30 @@ export async function loadReasoningTemplates(data) { | |||
| 1337 | $('<option>').val(template.name).text(template.name).appendTo(UI.$select); | 1340 | $('<option>').val(template.name).text(template.name).appendTo(UI.$select); |
| 1338 | } | 1341 | } |
| 1339 | 1342 | ||
| 1340 | if (!power_user.reasoning.name) { | 1343 | // No template name, need to migrate |
| 1341 | power_user.reasoning.name = reasoning_templates[0]?.name ?? ''; | 1344 | if (power_user.reasoning.name === undefined) { |
| 1345 | const defaultTemplate = reasoning_templates.find(p => p.name === DEFAULT_REASONING_TEMPLATE); | ||
| 1346 | if (defaultTemplate) { | ||
| 1347 | // If the reasoning settings were modified - migrate them to a custom template | ||
| 1348 | if (power_user.reasoning.prefix !== defaultTemplate.prefix || power_user.reasoning.suffix !== defaultTemplate.suffix || power_user.reasoning.separator !== defaultTemplate.separator) { | ||
| 1349 | /** @type {ReasoningTemplate} */ | ||
| 1350 | const data = { | ||
| 1351 | name: '[Migrated] Custom', | ||
| 1352 | prefix: power_user.reasoning.prefix, | ||
| 1353 | suffix: power_user.reasoning.suffix, | ||
| 1354 | separator: power_user.reasoning.separator, | ||
| 1355 | }; | ||
| 1356 | await getPresetManager('reasoning')?.savePreset(data.name, data); | ||
| 1357 | power_user.reasoning.name = data.name; | ||
| 1358 | } else { | ||
| 1359 | power_user.reasoning.name = defaultTemplate.name; | ||
| 1360 | } | ||
| 1361 | } else { | ||
| 1362 | // Template not found (deleted or content check skipped - leave blank) | ||
| 1363 | power_user.reasoning.name = ''; | ||
| 1364 | } | ||
| 1365 | |||
| 1366 | saveSettingsDebounced(); | ||
| 1342 | } | 1367 | } |
| 1343 | 1368 | ||
| 1344 | UI.$select.val(power_user.reasoning.name); | 1369 | UI.$select.val(power_user.reasoning.name); |