Compare commits

...

7 Commits

Author SHA1 Message Date
Cohee ace7b7f8dd
Merge 2e50d61590 into 694cf6f762 2024-05-06 14:28:16 +00:00
Cohee 694cf6f762 Fix field name 2024-05-06 17:27:43 +03:00
Cohee 83c77c1f18 Split group weight and trigger% 2024-05-06 17:00:42 +03:00
Cohee d54ccece5c
Merge pull request #2184 from bdashore3/fixed-slash-command
Fix the /send command
2024-05-06 16:25:09 +03:00
kingbri 96506947cb Messages + Instruct: Fix /send with name= if name is empty
If name is empty, don't try appending it to the message. This applies
for both instruct and non-instruct modes.

Signed-off-by: kingbri <bdashore3@proton.me>
2024-05-05 20:35:03 -04:00
based 2e50d61590 include optional source saving 2024-02-01 17:39:37 +10:00
based 8430212474 completely decouple proxies from the chat completion preset file 2024-02-01 15:46:12 +10:00
7 changed files with 166 additions and 33 deletions

View File

@ -360,6 +360,14 @@
flex: 2 !important;
}
.flex3 {
flex: 3;
}
.flex4 {
flex: 4;
}
.flexFlowColumn {
flex-flow: column;
}
@ -563,4 +571,4 @@ textarea:disabled {
height: 30px;
text-align: center;
padding: 5px;
}
}

View File

@ -2343,6 +2343,15 @@
<input id="openai_proxy_password" type="password" class="text_pole flex1" placeholder="" maxlength="5000" form="openai_form" autocomplete="off" />
<div id="openai_proxy_password_show" title="Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
</div>
<div class="">
<div class="range-block-title justifyLeft" id="proxy_current_source" data-i18n="Current source: ">
Current source:
</div>
<label for="openai_show_external_models" class="checkbox_label">
<input id="proxy_save_completion_source" type="checkbox" />
<span data-i18n="Save Model/Completion Source?">Save Model/Completion Source?</span>
</label>
</div>
</div>
</div>
<form id="openai_form" data-source="openai" action="javascript:void(null);" method="post" enctype="multipart/form-data">
@ -5197,7 +5206,7 @@
</div>
</div>
<div class="flex-container wide100p flexGap10">
<div class="flex1 flex-container flexFlowColumn flexNoGap">
<div class="flex4 flex-container flexFlowColumn flexNoGap">
<div class="flex-container justifySpaceBetween">
<small for="characterFilter" data-i18n="Filter to Character(s)">
Filter to Character(s)
@ -5217,7 +5226,7 @@
</select>
</div>
</div>
<div class="flex1 flex-container flexFlowColumn flexNoGap">
<div class="flex3 flex-container flexFlowColumn flexNoGap">
<div class="flex-container justifySpaceBetween">
<small for="group" data-i18n="Inclusion Group">
Inclusion Group
@ -5239,6 +5248,16 @@
<input type="text" class="text_pole margin0" name="group" rows="1" data-i18n="[placeholder]Only one entry with the same label will be activated" placeholder="Only one entry with the same label will be activated">
</div>
</div>
<div class="flex1 flex-container flexFlowColumn flexNoGap" data-i18n="[title]A relative likelihood of entry activation within the group" title="A relative likelihood of entry activation within the group">
<div class="flex-container justifySpaceBetween marginBot5">
<small for="groupWeight" data-i18n="Group Weight">
Group Weight
</small>
</div>
<div class="range-block-range">
<input type="number" class="text_pole margin0" name="groupWeight" rows="1" placeholder="100" min="0" max="999999">
</div>
</div>
</div>
<div name="WIEntryBottomControls" class="flex-container flex1 justifySpaceBetween world_entry_form_horizontal">
<div class="flex-container flexFlowColumn flexNoGap wi-enter-footer-text ">

View File

@ -4387,7 +4387,8 @@ function formatMessageHistoryItem(chatItem, isInstruct, forceOutputSequence) {
const itemName = chatItem.is_user ? chatItem['name'] : characterName;
const shouldPrependName = !isNarratorType;
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
// Don't include a name if it's empty
let textResult = chatItem?.name && shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
if (isInstruct) {
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceOutputSequence);

View File

@ -340,8 +340,11 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
}
const separator = power_user.instruct.wrap ? '\n' : '';
const textArray = includeNames ? [prefix, `${name}: ${mes}` + suffix] : [prefix, mes + suffix];
// Don't include the name if it's empty
const textArray = includeNames && name ? [prefix, `${name}: ${mes}` + suffix] : [prefix, mes + suffix];
const text = textArray.filter(x => x).join(separator);
return text;
}

View File

@ -358,6 +358,9 @@ export let proxies = [
name: 'None',
url: '',
password: '',
save_source: false,
model: '',
source: '',
},
];
export let selected_proxy = proxies[0];
@ -2713,7 +2716,6 @@ function loadOpenAISettings(data, settings) {
oai_settings.chat_completion_source = settings.chat_completion_source ?? default_settings.chat_completion_source;
oai_settings.api_url_scale = settings.api_url_scale ?? default_settings.api_url_scale;
oai_settings.show_external_models = settings.show_external_models ?? default_settings.show_external_models;
oai_settings.proxy_password = settings.proxy_password ?? default_settings.proxy_password;
oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill;
oai_settings.human_sysprompt_message = settings.human_sysprompt_message ?? default_settings.human_sysprompt_message;
oai_settings.image_inlining = settings.image_inlining ?? default_settings.image_inlining;
@ -2748,7 +2750,6 @@ function loadOpenAISettings(data, settings) {
$('#stream_toggle').prop('checked', oai_settings.stream_openai);
$('#websearch_toggle').prop('checked', oai_settings.websearch_cohere);
$('#api_url_scale').val(oai_settings.api_url_scale);
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#claude_assistant_prefill').val(oai_settings.assistant_prefill);
$('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message);
$('#openai_image_inlining').prop('checked', oai_settings.image_inlining);
@ -2836,11 +2837,6 @@ function loadOpenAISettings(data, settings) {
$('#seed_openai').val(oai_settings.seed);
$('#n_openai').val(oai_settings.n);
if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy;
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
$('.reverse_proxy_warning').toggle(oai_settings.reverse_proxy !== '');
$('#openai_logit_bias_preset').empty();
for (const preset of Object.keys(oai_settings.bias_presets)) {
const option = document.createElement('option');
@ -3050,8 +3046,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
new_example_chat_prompt: settings.new_example_chat_prompt,
continue_nudge_prompt: settings.continue_nudge_prompt,
bias_preset_selected: settings.bias_preset_selected,
reverse_proxy: settings.reverse_proxy,
proxy_password: settings.proxy_password,
max_context_unlocked: settings.max_context_unlocked,
wi_format: settings.wi_format,
scenario_format: settings.scenario_format,
@ -3435,7 +3429,6 @@ function onSettingsPresetChange() {
new_example_chat_prompt: ['#newexamplechat_prompt_textarea', 'new_example_chat_prompt', false],
continue_nudge_prompt: ['#continue_nudge_prompt_textarea', 'continue_nudge_prompt', false],
bias_preset_selected: ['#openai_logit_bias_preset', 'bias_preset_selected', false],
reverse_proxy: ['#openai_reverse_proxy', 'reverse_proxy', false],
wi_format: ['#wi_format_textarea', 'wi_format', false],
scenario_format: ['#scenario_format_textarea', 'scenario_format', false],
personality_format: ['#personality_format_textarea', 'personality_format', false],
@ -3446,7 +3439,6 @@ function onSettingsPresetChange() {
prompt_order: ['', 'prompt_order', false],
api_url_scale: ['#api_url_scale', 'api_url_scale', false],
show_external_models: ['#openai_show_external_models', 'show_external_models', true],
proxy_password: ['#openai_proxy_password', 'proxy_password', false],
assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false],
human_sysprompt_message: ['#claude_human_sysprompt_textarea', 'human_sysprompt_message', false],
use_ai21_tokenizer: ['#use_ai21_tokenizer', 'use_ai21_tokenizer', true],
@ -3889,6 +3881,7 @@ async function onModelChange() {
saveSettingsDebounced();
eventSource.emit(event_types.CHATCOMPLETION_MODEL_CHANGED, value);
$('#proxy_current_source').text(`Current source: ${oai_settings.chat_completion_source}/${retrieveModel()}`);
}
async function onOpenrouterModelSortChange() {
@ -4264,7 +4257,8 @@ export function loadProxyPresets(settings) {
} else {
proxies = proxyPresets;
}
//sort alphabetically
proxyPresets.sort((a, b) => a.name.localeCompare(b.name));
$('#openai_proxy_preset').empty();
for (const preset of proxyPresets) {
@ -4275,17 +4269,91 @@ export function loadProxyPresets(settings) {
$('#openai_proxy_preset').append(option);
}
$('#openai_proxy_preset').val(selected_proxy.name);
setProxyPreset(selected_proxy.name, selected_proxy.url, selected_proxy.password);
setProxyPreset(selected_proxy.name, selected_proxy.url, selected_proxy.password, selected_proxy.save_source, selected_proxy.model, selected_proxy.source);
}
function setProxyPreset(name, url, password) {
// two of the functions of all time
function retrieveModel() {
let model;
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
model = oai_settings.openai_model;
break;
case chat_completion_sources.CLAUDE:
model = oai_settings.claude_model;
break;
case chat_completion_sources.WINDOWAI:
model = oai_settings.windowai_model;
break;
case chat_completion_sources.OPENROUTER:
model = oai_settings.openrouter_model;
break;
case chat_completion_sources.AI21:
model = oai_settings.ai21_model;
break;
case chat_completion_sources.MISTRALAI:
model = oai_settings.mistralai_model;
break;
case chat_completion_sources.CUSTOM:
model = oai_settings.custom_model;
break;
default:
model = '';
}
return model;
}
function setModel(model) {
switch (oai_settings.chat_completion_source) {
case chat_completion_sources.OPENAI:
oai_settings.openai_model = model;
$('#model_openai_select').val(model);
break;
case chat_completion_sources.CLAUDE:
oai_settings.claude_model = model;
$('#model_claude_select').val(model);
break;
case chat_completion_sources.WINDOWAI:
oai_settings.windowai_model = model;
$('#model_windowai_select').val(model);
break;
case chat_completion_sources.MAKERSUITE:
oai_settings.google_model = model;
$('#model_google_select').val(model);
break;
case chat_completion_sources.OPENROUTER:
oai_settings.openrouter_model = model;
$('#model_openrouter_select').val(model);
break;
case chat_completion_sources.AI21:
oai_settings.ai21_model = model;
$('#model_ai21_select').val(model);
break;
case chat_completion_sources.MISTRALAI:
oai_settings.mistralai_model = model;
$('#model_mistralai_select').val(model);
break;
default:
console.log('Invalid chat completion source');
}
toggleChatCompletionForms();
}
function setProxyPreset(name, url, password, save_source, update) {
name = name.trim();
const preset = proxies.find(p => p.name === name);
const model = save_source ? (update ? retrieveModel() : preset.model) : '';
const source = save_source ? (update ? oai_settings.chat_completion_source : preset.source) : '';
if (preset) {
preset.url = url;
preset.password = password;
preset.save_source = save_source;
preset.model = model;
preset.source = source;
selected_proxy = preset;
} else {
let new_proxy = { name, url, password };
let new_proxy = { name, url, password, save_source, model, source };
proxies.push(new_proxy);
selected_proxy = new_proxy;
}
@ -4295,7 +4363,15 @@ function setProxyPreset(name, url, password) {
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
oai_settings.proxy_password = password;
$('#openai_proxy_password').val(oai_settings.proxy_password);
$('#proxy_save_completion_source').prop('checked', save_source === undefined ? false : save_source);
if (save_source && model && source) {
oai_settings.chat_completion_source = source;
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
setModel(model);
}
reconnectOpenAi();
$('.reverse_proxy_warning').toggle(oai_settings.reverse_proxy !== '');
}
function onProxyPresetChange() {
@ -4303,7 +4379,7 @@ function onProxyPresetChange() {
const selectedPreset = proxies.find(preset => preset.name === value);
if (selectedPreset) {
setProxyPreset(selectedPreset.name, selectedPreset.url, selectedPreset.password);
setProxyPreset(selectedPreset.name, selectedPreset.url, selectedPreset.password, selectedPreset.save_source);
} else {
console.error(`Proxy preset "${value}" not found in proxies array.`);
}
@ -4311,11 +4387,12 @@ function onProxyPresetChange() {
}
$('#save_proxy').on('click', async function () {
const presetName = $('#openai_reverse_proxy_name').val();
const reverseProxy = $('#openai_reverse_proxy').val();
const proxyPassword = $('#openai_proxy_password').val();
const presetName = $('#openai_reverse_proxy_name').val().trim();
const reverseProxy = $('#openai_reverse_proxy').val().trim();
const proxyPassword = $('#openai_proxy_password').val().trim();
const saveSource = $('#proxy_save_completion_source').is(':checked');
setProxyPreset(presetName, reverseProxy, proxyPassword);
setProxyPreset(presetName, reverseProxy, proxyPassword, saveSource, saveSource);
saveSettingsDebounced();
toastr.success('Proxy Saved');
if ($('#openai_proxy_preset').val() !== presetName) {
@ -4329,7 +4406,7 @@ $('#save_proxy').on('click', async function () {
});
$('#delete_proxy').on('click', async function () {
const presetName = $('#openai_reverse_proxy_name').val();
const presetName = $('#openai_reverse_proxy_name').val().trim();
const index = proxies.findIndex(preset => preset.name === presetName);
if (index !== -1) {
@ -4340,7 +4417,7 @@ $('#delete_proxy').on('click', async function () {
const newIndex = Math.max(0, index - 1);
selected_proxy = proxies[newIndex];
} else {
selected_proxy = { name: 'None', url: '', password: '' };
selected_proxy = { name: 'None', url: '', password: '', save_source: false, model: '', source: '' };
}
$('#openai_reverse_proxy_name').val(selected_proxy.name);
@ -4348,7 +4425,11 @@ $('#delete_proxy').on('click', async function () {
$('#openai_reverse_proxy').val(selected_proxy.url);
oai_settings.proxy_password = selected_proxy.password;
$('#openai_proxy_password').val(selected_proxy.password);
if (selected_proxy.save_source) {
oai_settings.chat_completion_source = selected_proxy.source;
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
setModel(selected_proxy.model);
}
saveSettingsDebounced();
$('#openai_proxy_preset').val(selected_proxy.name);
toastr.success('Proxy Deleted');

View File

@ -74,6 +74,7 @@ const SORT_ORDER_KEY = 'world_info_sort_order';
const METADATA_KEY = 'world_info';
const DEFAULT_DEPTH = 4;
const DEFAULT_WEIGHT = 100;
const MAX_SCAN_DEPTH = 1000;
/**
@ -1093,6 +1094,7 @@ const originalDataKeyMap = {
'automationId': 'extensions.automation_id',
'vectorized': 'extensions.vectorized',
'groupOverride': 'extensions.group_override',
'groupWeight': 'extensions.group_weight',
};
/** Checks the state of the current search, and adds/removes the search sorting option accordingly */
@ -1466,11 +1468,24 @@ function getWorldEntry(name, data, entry) {
const uid = $(this).data('uid');
const value = $(this).prop('checked');
data.entries[uid].groupOverride = value;
setOriginalDataValue(data, uid, 'extensions.groupOverride', data.entries[uid].groupOverride);
setOriginalDataValue(data, uid, 'extensions.group_override', data.entries[uid].groupOverride);
saveWorldInfo(name, data);
});
groupOverrideInput.prop('checked', entry.groupOverride).trigger('input');
// group weight
const groupWeightInput = template.find('input[name="groupWeight"]');
groupWeightInput.data('uid', entry.uid);
groupWeightInput.on('input', function () {
const uid = $(this).data('uid');
const value = Number($(this).val());
data.entries[uid].groupWeight = !isNaN(value) ? Math.abs(value) : 0;
setOriginalDataValue(data, uid, 'extensions.group_weight', data.entries[uid].groupWeight);
saveWorldInfo(name, data);
});
groupWeightInput.val(entry.groupWeight).trigger('input');
// probability
if (entry.probability === undefined) {
entry.probability = null;
@ -1971,6 +1986,7 @@ const newEntryTemplate = {
depth: DEFAULT_DEPTH,
group: '',
groupOverride: false,
groupWeight: DEFAULT_WEIGHT,
scanDepth: null,
caseSensitive: null,
matchWholeWords: null,
@ -2424,7 +2440,7 @@ async function checkWorldInfo(chat, maxContext) {
for (const entry of newEntries) {
const rollValue = Math.random() * 100;
if (!entry.group && entry.useProbability && rollValue > entry.probability) {
if (entry.useProbability && rollValue > entry.probability) {
console.debug(`WI entry ${entry.uid} ${entry.key} failed probability check, skipping`);
failedProbabilityChecks.add(entry);
continue;
@ -2633,14 +2649,14 @@ function filterByInclusionGroups(newEntries, allActivatedEntries, buffer) {
continue;
}
// Do weighted random using probability of entry as weight
const totalWeight = group.reduce((acc, item) => acc + item.probability, 0);
// Do weighted random using entry's weight
const totalWeight = group.reduce((acc, item) => acc + (item.groupWeight ?? DEFAULT_WEIGHT), 0);
const rollValue = Math.random() * totalWeight;
let currentWeight = 0;
let winner = null;
for (const entry of group) {
currentWeight += entry.probability;
currentWeight += (entry.groupWeight ?? DEFAULT_WEIGHT);
if (rollValue <= currentWeight) {
console.debug(`Activated inclusion group '${key}' with roll winner entry '${entry.uid}'`, entry);
@ -2684,6 +2700,7 @@ function convertAgnaiMemoryBook(inputObj) {
useProbability: false,
group: '',
groupOverride: false,
groupWeight: DEFAULT_WEIGHT,
scanDepth: null,
caseSensitive: null,
matchWholeWords: null,
@ -2721,6 +2738,7 @@ function convertRisuLorebook(inputObj) {
useProbability: entry.activationPercent ?? false,
group: '',
groupOverride: false,
groupWeight: DEFAULT_WEIGHT,
scanDepth: null,
caseSensitive: null,
matchWholeWords: null,
@ -2763,6 +2781,7 @@ function convertNovelLorebook(inputObj) {
useProbability: false,
group: '',
groupOverride: false,
groupWeight: DEFAULT_WEIGHT,
scanDepth: null,
caseSensitive: null,
matchWholeWords: null,
@ -2806,6 +2825,7 @@ function convertCharacterBook(characterBook) {
selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND_ANY,
group: entry.extensions?.group ?? '',
groupOverride: entry.extensions?.group_override ?? false,
groupWeight: entry.extensions?.group_weight ?? DEFAULT_WEIGHT,
scanDepth: entry.extensions?.scan_depth ?? null,
caseSensitive: entry.extensions?.case_sensitive ?? null,
matchWholeWords: entry.extensions?.match_whole_words ?? null,

View File

@ -434,6 +434,7 @@ function convertWorldInfoToCharacterBook(name, entries) {
selectiveLogic: entry.selectiveLogic ?? 0,
group: entry.group ?? '',
group_override: entry.groupOverride ?? false,
group_weight: entry.groupWeight ?? null,
prevent_recursion: entry.preventRecursion ?? false,
scan_depth: entry.scanDepth ?? null,
match_whole_words: entry.matchWholeWords ?? null,