Adjust reasoning template migration procedure
| @@ -55,7 +55,7 @@ import { POPUP_TYPE, callGenericPopup } from './popup.js'; | ||
| 55 | 55 | import { loadSystemPrompts } from './sysprompt.js'; |
| 56 | 56 | import { fuzzySearchCategories } from './filters.js'; |
| 57 | 57 | import { accountStorage } from './util/AccountStorage.js'; |
| 58 | 58 | import { DEFAULT_REASONING_TEMPLATE, loadReasoningTemplates } from './reasoning.js'; |
| 59 | 59 | |
| 60 | 60 | export { |
| 61 | 61 | loadPowerUserSettings, |
| @@ -258,7 +258,7 @@ let power_user = { | ||
| 258 | 258 | }, |
| 259 | 259 | |
| 260 | 260 | reasoning: { |
| 261 | 261 | name: 'DeepSeek'DEFAULT_REASONING_TEMPLATE, |
| 262 | 262 | auto_parse: false, |
| 263 | 263 | add_to_prompts: false, |
| 264 | 264 | auto_expand: false, |
| @@ -8,6 +8,7 @@ import { MacrosParser } from './macros.js'; | ||
| 8 | 8 | import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js'; |
| 9 | 9 | import { Popup } from './popup.js'; |
| 10 | 10 | import { performFuzzySearch, power_user } from './power-user.js'; |
| 11 | +import { getPresetManager } from './preset-manager.js'; | |
| 11 | 12 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| 12 | 13 | import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; |
| 13 | 14 | import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| @@ -29,6 +30,8 @@ import { copyText, escapeRegex, isFalseBoolean, isTrueBoolean, setDatasetPropert | ||
| 29 | 30 | */ |
| 30 | 31 | export const reasoning_templates = []; |
| 31 | 32 | |
| 33 | +export const DEFAULT_REASONING_TEMPLATE = 'DeepSeek'; | |
| 34 | + | |
| 32 | 35 | /** |
| 33 | 36 | * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings |
| 34 | 37 | * @readonly |
| @@ -1337,8 +1340,30 @@ export async function loadReasoningTemplates(data) { | ||
| 1337 | 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 | 1369 | UI.$select.val(power_user.reasoning.name); |