Add uuid to CC logit bias entries

3f7b91a4ebaf3cb1c85755bbc92591f05e5a6096

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +33 -13Ignore whitespace
default/content/settings.json+4 -0
@@ -599,18 +599,22 @@
599599 "Default (none)": [],
600600 "Anti-bond": [
601601 {
602+ "id": "22154f79-dd98-41bc-8e34-87015d6a0eaf",
602603 "text": " bond",
603604 "value": -50
604605 },
605606 {
607+ "id": "8ad2d5c4-d8ef-49e4-bc5e-13e7f4690e0f",
606608 "text": " future",
607609 "value": -50
608610 },
609611 {
612+ "id": "52a4b280-0956-4940-ac52-4111f83e4046",
610613 "text": " bonding",
611614 "value": -50
612615 },
613616 {
617+ "id": "e63037c7-c9d1-4724-ab2d-7756008b433b",
614618 "text": " connection",
615619 "value": -25
616620 }
public/scripts/openai.js+28 -12
@@ -60,6 +60,7 @@ import {
6060 parseJsonFile,
6161 resetScrollHeight,
6262 stringFormat,
63+ uuidv4,
6364} from './utils.js';
6465import { countTokensOpenAIAsync, getTokenizerModel } from './tokenizers.js';
6566import { isMobile } from './RossAscends-mods.js';
@@ -107,10 +108,10 @@ const default_group_nudge_prompt = '[Write the next reply only as {{char}}.]';
107108const default_bias_presets = {
108109 [default_bias]: [],
109110 'Anti-bond': [
110111 { id: '22154f79-dd98-41bc-8e34-87015d6a0eaf', text: ' bond', value: -50 },
111112 { id: '8ad2d5c4-d8ef-49e4-bc5e-13e7f4690e0f', text: ' future', value: -50 },
112113 { id: '52a4b280-0956-4940-ac52-4111f83e4046', text: ' bonding', value: -50 },
113114 { id: 'e63037c7-c9d1-4724-ab2d-7756008b433b', text: ' connection', value: -25 },
114115 ],
115116};
116117
@@ -3177,6 +3178,14 @@ function loadOpenAISettings(data, settings) {
31773178
31783179 $('#openai_logit_bias_preset').empty();
31793180 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+ }
31803189 const option = document.createElement('option');
31813190 option.innerText = preset;
31823191 option.value = preset;
@@ -3465,7 +3474,7 @@ function onLogitBiasPresetChange() {
34653474 }
34663475
34673476 oai_settings.bias_preset_selected = value;
34683477 const list = $('.openai_logit_bias_list');
34693478 list.empty();
34703479
34713480 for (const entry of preset) {
@@ -3487,9 +3496,9 @@ function onLogitBiasPresetChange() {
34873496 stop: function () {
34883497 const order = [];
34893498 list.children().each(function () {
34903499 order.unshift(parseInt($(this).data('id')));
34913500 });
34923501 preset.sort((a, b) => order.indexOf(preset.indexOf(a).id) - order.indexOf(preset.indexOf(b).id));
34933502 console.log('Logit bias reordered:', preset);
34943503 saveSettingsDebounced();
34953504 },
@@ -3500,7 +3509,7 @@ function onLogitBiasPresetChange() {
35003509}
35013510
35023511function createNewLogitBiasEntry() {
35033512 const entry = { id: uuidv4(), text: '', value: 0 };
35043513 oai_settings.bias_presets[oai_settings.bias_preset_selected].push(entry);
35053514 biasCache = undefined;
35063515 createLogitBiasListItem(entry);
@@ -3508,11 +3517,14 @@ function createNewLogitBiasEntry() {
35083517}
35093518
35103519function 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;
35123524 const template = $('#openai_logit_bias_template .openai_logit_bias_form').clone();
35133525 template.data('id', id);
35143526 template.find('.openai_logit_bias_text').val(entry.text).on('input', function () {
35153527 oai_settings.bias_presets[oai_settings.bias_preset_selected][id]entry.text = String($(this).val());
35163528 biasCache = undefined;
35173529 saveSettingsDebounced();
35183530 });
@@ -3531,13 +3543,17 @@ function createLogitBiasListItem(entry) {
35313543 value = max;
35323544 }
35333545
35343546 oai_settings.bias_presets[oai_settings.bias_preset_selected][id]entry.value = value;
35353547 biasCache = undefined;
35363548 saveSettingsDebounced();
35373549 });
35383550 template.find('.openai_logit_bias_remove').on('click', function () {
35393551 $(this).closest('.openai_logit_bias_form').remove();
35403552 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+ }
35413557 onLogitBiasPresetChange();
35423558 });
35433559 $('.openai_logit_bias_list').prepend(template);
public/style.css+1 -1
@@ -5179,7 +5179,7 @@ body:not(.movingUI) .drawer-content.maximized {
51795179 width: 100%;
51805180 height: 100%;
51815181 opacity: 0.8;
51825182 min-height: 3rem2.5em;
51835183}
51845184
51855185.openai_restorable,