diff --git a/default/content/presets/openai/Default.json b/default/content/presets/openai/Default.json
index 8c4f0f6f3..ab62d001d 100644
--- a/default/content/presets/openai/Default.json
+++ b/default/content/presets/openai/Default.json
@@ -7,7 +7,6 @@
"nsfw_toggle": true,
"enhance_definitions": false,
"wrap_in_quotes": false,
- "names_in_completion": false,
"nsfw_first": false,
"main_prompt": "Write {{char}}'s next reply in a fictional chat between {{char}} and {{user}}. Write 1 reply only in internet RP style, italicize actions, and avoid quotation marks. Use markdown. Be proactive, creative, and drive the plot and conversation forward. Write at least 1 paragraph, up to 4. Always stay in character and avoid repetition.",
"nsfw_prompt": "NSFW/Smut is allowed. Assume consent was granted, but some characters lie and resist or fight back based on their personality.",
diff --git a/default/settings.json b/default/settings.json
index 9156bdf44..3c8faadbf 100644
--- a/default/settings.json
+++ b/default/settings.json
@@ -456,7 +456,6 @@
"openai_max_context": 4095,
"openai_max_tokens": 300,
"wrap_in_quotes": false,
- "names_in_completion": false,
"prompts": [
{
"name": "Main Prompt",
diff --git a/public/index.html b/public/index.html
index 0ff62117d..7c67bdccd 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1623,6 +1623,39 @@
-
-
- Add character names
-
-
- Send names in the message objects. Helps the model to associate messages with characters.
-
-
diff --git a/public/scripts/openai.js b/public/scripts/openai.js
index 9d6718241..20ed56f00 100644
--- a/public/scripts/openai.js
+++ b/public/scripts/openai.js
@@ -171,6 +171,12 @@ export const chat_completion_sources = {
CUSTOM: 'custom',
};
+const character_names_behavior = {
+ NONE: 0,
+ COMPLETION: 1,
+ CONTENT: 2,
+};
+
const prefixMap = selected_group ? {
assistant: '',
user: '',
@@ -197,7 +203,6 @@ const default_settings = {
openai_max_context: max_4k,
openai_max_tokens: 300,
wrap_in_quotes: false,
- names_in_completion: false,
...chatCompletionDefaultPrompts,
...promptManagerDefaultPromptOrders,
send_if_empty: '',
@@ -245,6 +250,7 @@ const default_settings = {
image_inlining: false,
bypass_status_check: false,
continue_prefill: false,
+ names_behavior: character_names_behavior.NONE,
seed: -1,
n: 1,
};
@@ -264,7 +270,6 @@ const oai_settings = {
openai_max_context: max_4k,
openai_max_tokens: 300,
wrap_in_quotes: false,
- names_in_completion: false,
...chatCompletionDefaultPrompts,
...promptManagerDefaultPromptOrders,
send_if_empty: '',
@@ -312,6 +317,7 @@ const oai_settings = {
image_inlining: false,
bypass_status_check: false,
continue_prefill: false,
+ names_behavior: character_names_behavior.NONE,
seed: -1,
n: 1,
};
@@ -466,11 +472,22 @@ function setOpenAIMessages(chat) {
}
// for groups or sendas command - prepend a character's name
- if (!oai_settings.names_in_completion) {
- if (selected_group || (chat[j].force_avatar && chat[j].name !== name1 && chat[j].extra?.type !== system_message_types.NARRATOR)) {
- content = `${chat[j].name}: ${content}`;
- }
+ switch (oai_settings.names_behavior) {
+ case character_names_behavior.NONE:
+ if (selected_group || (chat[j].force_avatar && chat[j].name !== name1 && chat[j].extra?.type !== system_message_types.NARRATOR)) {
+ content = `${chat[j].name}: ${content}`;
+ }
+ break;
+ case character_names_behavior.CONTENT:
+ if (chat[j].extra?.type !== system_message_types.NARRATOR) {
+ content = `${chat[j].name}: ${content}`;
+ }
+ break;
+ default:
+ // No action for character_names_behavior.COMPLETION
+ break;
}
+
// remove caret return (waste of tokens)
content = content.replace(/\r/gm, '');
@@ -730,7 +747,7 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul
prompt.identifier = `chatHistory-${messages.length - index}`;
const chatMessage = Message.fromPrompt(promptManager.preparePrompt(prompt));
- if (true === promptManager.serviceSettings.names_in_completion && prompt.name) {
+ if (promptManager.serviceSettings.names_behavior === character_names_behavior.COMPLETION && prompt.name) {
const messageName = promptManager.isValidName(prompt.name) ? prompt.name : promptManager.sanitizeName(prompt.name);
chatMessage.setName(messageName);
}
@@ -1612,12 +1629,6 @@ async function sendOpenAIRequest(type, messages, signal) {
delete generate_data.stop;
}
- // Remove logit bias and stop strings if it's not supported by the model
- if (isOAI && oai_settings.openai_model.includes('vision') || isOpenRouter && oai_settings.openrouter_model.includes('vision')) {
- delete generate_data.logit_bias;
- delete generate_data.stop;
- }
-
// Proxy is only supported for Claude, OpenAI and Mistral
if (oai_settings.reverse_proxy && [chat_completion_sources.CLAUDE, chat_completion_sources.OPENAI, chat_completion_sources.MISTRALAI].includes(oai_settings.chat_completion_source)) {
validateReverseProxy();
@@ -1630,6 +1641,13 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['logprobs'] = 5;
}
+ // Remove logit bias, logprobs and stop strings if it's not supported by the model
+ if (isOAI && oai_settings.openai_model.includes('vision') || isOpenRouter && oai_settings.openrouter_model.includes('vision')) {
+ delete generate_data.logit_bias;
+ delete generate_data.stop;
+ delete generate_data.logprobs;
+ }
+
if (isClaude) {
generate_data['top_k'] = Number(oai_settings.top_k_openai);
generate_data['claude_use_sysprompt'] = oai_settings.claude_use_sysprompt;
@@ -2554,9 +2572,14 @@ function loadOpenAISettings(data, settings) {
oai_settings.continue_nudge_prompt = settings.continue_nudge_prompt ?? default_settings.continue_nudge_prompt;
oai_settings.squash_system_messages = settings.squash_system_messages ?? default_settings.squash_system_messages;
oai_settings.continue_prefill = settings.continue_prefill ?? default_settings.continue_prefill;
+ oai_settings.names_behavior = settings.names_behavior ?? default_settings.names_behavior;
+
+ // Migrate from old settings
+ if (settings.names_in_completion === true) {
+ oai_settings.names_behavior = character_names_behavior.COMPLETION;
+ }
if (settings.wrap_in_quotes !== undefined) oai_settings.wrap_in_quotes = !!settings.wrap_in_quotes;
- if (settings.names_in_completion !== undefined) oai_settings.names_in_completion = !!settings.names_in_completion;
if (settings.openai_model !== undefined) oai_settings.openai_model = settings.openai_model;
if (settings.use_ai21_tokenizer !== undefined) { oai_settings.use_ai21_tokenizer = !!settings.use_ai21_tokenizer; oai_settings.use_ai21_tokenizer ? ai21_max = 8191 : ai21_max = 9200; }
if (settings.use_google_tokenizer !== undefined) oai_settings.use_google_tokenizer = !!settings.use_google_tokenizer;
@@ -2592,7 +2615,6 @@ function loadOpenAISettings(data, settings) {
$('#openai_max_tokens').val(oai_settings.openai_max_tokens);
$('#wrap_in_quotes').prop('checked', oai_settings.wrap_in_quotes);
- $('#names_in_completion').prop('checked', oai_settings.names_in_completion);
$('#jailbreak_system').prop('checked', oai_settings.jailbreak_system);
$('#openai_show_external_models').prop('checked', oai_settings.show_external_models);
$('#openai_external_category').toggle(oai_settings.show_external_models);
@@ -2666,10 +2688,26 @@ function loadOpenAISettings(data, settings) {
oai_settings.chat_completion_source = chat_completion_sources.MAKERSUITE;
}
+ setNamesBehaviorControls();
+
$('#chat_completion_source').val(oai_settings.chat_completion_source).trigger('change');
$('#oai_max_context_unlocked').prop('checked', oai_settings.max_context_unlocked);
}
+function setNamesBehaviorControls() {
+ switch (oai_settings.names_behavior) {
+ case character_names_behavior.NONE:
+ $('#character_names_none').prop('checked', true);
+ break;
+ case character_names_behavior.COMPLETION:
+ $('#character_names_completion').prop('checked', true);
+ break;
+ case character_names_behavior.CONTENT:
+ $('#character_names_content').prop('checked', true);
+ break;
+ }
+}
+
async function getStatusOpen() {
if (oai_settings.chat_completion_source == chat_completion_sources.WINDOWAI) {
let status;
@@ -2794,7 +2832,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
openai_max_context: settings.openai_max_context,
openai_max_tokens: settings.openai_max_tokens,
wrap_in_quotes: settings.wrap_in_quotes,
- names_in_completion: settings.names_in_completion,
+ names_behavior: settings.names_behavior,
send_if_empty: settings.send_if_empty,
jailbreak_prompt: settings.jailbreak_prompt,
jailbreak_system: settings.jailbreak_system,
@@ -3172,7 +3210,7 @@ function onSettingsPresetChange() {
openai_max_context: ['#openai_max_context', 'openai_max_context', false],
openai_max_tokens: ['#openai_max_tokens', 'openai_max_tokens', false],
wrap_in_quotes: ['#wrap_in_quotes', 'wrap_in_quotes', true],
- names_in_completion: ['#names_in_completion', 'names_in_completion', true],
+ names_behavior: ['#names_behavior', 'names_behavior', false],
send_if_empty: ['#send_if_empty_textarea', 'send_if_empty', false],
impersonation_prompt: ['#impersonation_prompt_textarea', 'impersonation_prompt', false],
new_chat_prompt: ['#newchat_prompt_textarea', 'new_chat_prompt', false],
@@ -3209,6 +3247,11 @@ function onSettingsPresetChange() {
const preset = structuredClone(openai_settings[openai_setting_names[oai_settings.preset_settings_openai]]);
+ // Migrate old settings
+ if (preset.names_in_completion === true && preset.names_behavior === undefined) {
+ preset.names_behavior = character_names_behavior.COMPLETION;
+ }
+
const updateInput = (selector, value) => $(selector).val(value).trigger('input');
const updateCheckbox = (selector, value) => $(selector).prop('checked', value).trigger('input');
@@ -4077,11 +4120,6 @@ $(document).ready(async function () {
saveSettingsDebounced();
});
- $('#names_in_completion').on('change', function () {
- oai_settings.names_in_completion = !!$('#names_in_completion').prop('checked');
- saveSettingsDebounced();
- });
-
$('#send_if_empty_textarea').on('input', function () {
oai_settings.send_if_empty = String($('#send_if_empty_textarea').val());
saveSettingsDebounced();
@@ -4299,6 +4337,27 @@ $(document).ready(async function () {
saveSettingsDebounced();
});
+ $('#names_behavior').on('input', function () {
+ oai_settings.names_behavior = Number($(this).val());
+ setNamesBehaviorControls();
+ saveSettingsDebounced();
+ });
+
+ $('#character_names_none').on('input', function () {
+ oai_settings.names_behavior = character_names_behavior.NONE;
+ saveSettingsDebounced();
+ });
+
+ $('#character_names_completion').on('input', function () {
+ oai_settings.names_behavior = character_names_behavior.COMPLETION;
+ saveSettingsDebounced();
+ });
+
+ $('#character_names_content').on('input', function () {
+ oai_settings.names_behavior = character_names_behavior.CONTENT;
+ saveSettingsDebounced();
+ });
+
$(document).on('input', '#openai_settings .autoSetHeight', function () {
resetScrollHeight($(this));
});