Add uuid to CC logit bias entries

3f7b91a4ebaf3cb1c85755bbc92591f05e5a6096

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

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