Add uuid to CC logit bias entries
| @@ -599,18 +599,22 @@ | ||
| 599 | 599 | "Default (none)": [], |
| 600 | 600 | "Anti-bond": [ |
| 601 | 601 | { |
| 602 | + "id": "22154f79-dd98-41bc-8e34-87015d6a0eaf", | |
| 602 | 603 | "text": " bond", |
| 603 | 604 | "value": -50 |
| 604 | 605 | }, |
| 605 | 606 | { |
| 607 | + "id": "8ad2d5c4-d8ef-49e4-bc5e-13e7f4690e0f", | |
| 606 | 608 | "text": " future", |
| 607 | 609 | "value": -50 |
| 608 | 610 | }, |
| 609 | 611 | { |
| 612 | + "id": "52a4b280-0956-4940-ac52-4111f83e4046", | |
| 610 | 613 | "text": " bonding", |
| 611 | 614 | "value": -50 |
| 612 | 615 | }, |
| 613 | 616 | { |
| 617 | + "id": "e63037c7-c9d1-4724-ab2d-7756008b433b", | |
| 614 | 618 | "text": " connection", |
| 615 | 619 | "value": -25 |
| 616 | 620 | } |
| @@ -60,6 +60,7 @@ import { | ||
| 60 | 60 | parseJsonFile, |
| 61 | 61 | resetScrollHeight, |
| 62 | 62 | stringFormat, |
| 63 | + uuidv4, | |
| 63 | 64 | } from './utils.js'; |
| 64 | 65 | import { countTokensOpenAIAsync, getTokenizerModel } from './tokenizers.js'; |
| 65 | 66 | import { isMobile } from './RossAscends-mods.js'; |
| @@ -107,10 +108,10 @@ const default_group_nudge_prompt = '[Write the next reply only as {{char}}.]'; | ||
| 107 | 108 | const default_bias_presets = { |
| 108 | 109 | [default_bias]: [], |
| 109 | 110 | 'Anti-bond': [ |
| 110 | 111 | { id: '22154f79-dd98-41bc-8e34-87015d6a0eaf', text: ' bond', value: -50 }, |
| 111 | 112 | { id: '8ad2d5c4-d8ef-49e4-bc5e-13e7f4690e0f', text: ' future', value: -50 }, |
| 112 | 113 | { id: '52a4b280-0956-4940-ac52-4111f83e4046', text: ' bonding', value: -50 }, |
| 113 | 114 | { id: 'e63037c7-c9d1-4724-ab2d-7756008b433b', text: ' connection', value: -25 }, |
| 114 | 115 | ], |
| 115 | 116 | }; |
| 116 | 117 | |
| @@ -3177,6 +3178,14 @@ function loadOpenAISettings(data, settings) { | ||
| 3177 | 3178 | |
| 3178 | 3179 | $('#openai_logit_bias_preset').empty(); |
| 3179 | 3180 | for (const preset of Object.keys(oai_settings.bias_presets)) { |
| 3181 | + // Backfill missing IDs | |
| 3182 | + if (Array.isArray(oai_settings.bias_presets[preset])) { | |
| 3183 | + oai_settings.bias_presets[preset].forEach((bias) => { | |
| 3184 | + if (bias && !bias.id) { | |
| 3185 | + bias.id = uuidv4(); | |
| 3186 | + } | |
| 3187 | + }); | |
| 3188 | + } | |
| 3180 | 3189 | const option = document.createElement('option'); |
| 3181 | 3190 | option.innerText = preset; |
| 3182 | 3191 | option.value = preset; |
| @@ -3487,9 +3496,9 @@ function onLogitBiasPresetChange() { | ||
| 3487 | 3496 | stop: function () { |
| 3488 | 3497 | const order = []; |
| 3489 | 3498 | list.children().each(function () { |
| 3490 | 3499 | order.unshift(parseInt($(this).data('id'))); |
| 3491 | 3500 | }); |
| 3492 | 3501 | preset.sort((a, b) => order.indexOf(preset.indexOf(a).id) - order.indexOf(preset.indexOf(b).id)); |
| 3493 | 3502 | console.log('Logit bias reordered:', preset); |
| 3494 | 3503 | saveSettingsDebounced(); |
| 3495 | 3504 | }, |
| @@ -3500,7 +3509,7 @@ function onLogitBiasPresetChange() { | ||
| 3500 | 3509 | } |
| 3501 | 3510 | |
| 3502 | 3511 | function createNewLogitBiasEntry() { |
| 3503 | 3512 | const entry = { id: uuidv4(), text: '', value: 0 }; |
| 3504 | 3513 | oai_settings.bias_presets[oai_settings.bias_preset_selected].push(entry); |
| 3505 | 3514 | biasCache = undefined; |
| 3506 | 3515 | createLogitBiasListItem(entry); |
| @@ -3508,11 +3517,14 @@ function createNewLogitBiasEntry() { | ||
| 3508 | 3517 | } |
| 3509 | 3518 | |
| 3510 | 3519 | function createLogitBiasListItem(entry) { |
| 3511 | - const id = oai_settings.bias_presets[oai_settings.bias_preset_selected].indexOf(entry); | |
| 3520 | + if (!entry.id) { | |
| 3521 | + entry.id = uuidv4(); | |
| 3522 | + } | |
| 3523 | + const id = entry.id; | |
| 3512 | 3524 | const template = $('#openai_logit_bias_template .openai_logit_bias_form').clone(); |
| 3513 | 3525 | template.data('id', id); |
| 3514 | 3526 | template.find('.openai_logit_bias_text').val(entry.text).on('input', function () { |
| 3515 | 3527 | oai_settings.bias_presets[oai_settings.bias_preset_selected][id]entry.text = String($(this).val()); |
| 3516 | 3528 | biasCache = undefined; |
| 3517 | 3529 | saveSettingsDebounced(); |
| 3518 | 3530 | }); |
| @@ -3531,13 +3543,17 @@ function createLogitBiasListItem(entry) { | ||
| 3531 | 3543 | value = max; |
| 3532 | 3544 | } |
| 3533 | 3545 | |
| 3534 | 3546 | oai_settings.bias_presets[oai_settings.bias_preset_selected][id]entry.value = value; |
| 3535 | 3547 | biasCache = undefined; |
| 3536 | 3548 | saveSettingsDebounced(); |
| 3537 | 3549 | }); |
| 3538 | 3550 | template.find('.openai_logit_bias_remove').on('click', function () { |
| 3539 | 3551 | $(this).closest('.openai_logit_bias_form').remove(); |
| 3540 | 3552 | const preset = oai_settings.bias_presets[oai_settings.bias_preset_selected].splice(id, 1); |
| 3553 | + const index = preset.findIndex(item => item.id === id); | |
| 3554 | + if (index >= 0) { | |
| 3555 | + preset.splice(index, 1); | |
| 3556 | + } | |
| 3541 | 3557 | onLogitBiasPresetChange(); |
| 3542 | 3558 | }); |
| 3543 | 3559 | $('.openai_logit_bias_list').prepend(template); |
| @@ -5179,7 +5179,7 @@ body:not(.movingUI) .drawer-content.maximized { | ||
| 5179 | 5179 | width: 100%; |
| 5180 | 5180 | height: 100%; |
| 5181 | 5181 | opacity: 0.8; |
| 5182 | 5182 | min-height: 3rem2.5em; |
| 5183 | 5183 | } |
| 5184 | 5184 | |
| 5185 | 5185 | .openai_restorable, |