mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-09 16:40:10 +01:00
Add restore button, def hum message, claude check
This commit is contained in:
parent
7835a1360f
commit
50ece13752
@ -1538,8 +1538,13 @@
|
||||
<span data-i18n="Exclude the 'Human: ' prefix from being added to the beginning of the prompt.">Exclude the 'Human: ' prefix from being added to the beginning of the prompt. Instead, place it between the sysprompt and the first message with the role 'assistant'(right before 'Chat History', by default).</span>
|
||||
</div>
|
||||
<div id="claude_human_sysprompt_message_block" data-source="claude" class="wide100p">
|
||||
<span id="claude_human_sysprompt_message_text" data-i18n="Human: first message">Human: first message</span>
|
||||
<textarea id="claude_human_sysprompt_message" class="text_pole textarea_compact" name="human_sysprompt_message autoSetHeight" rows="3" maxlength="10000" data-i18n="[placeholder]Your message, instruction, etc... WHEN EMPTY and no manually added Human's message found between sysprompt and the first assistant message(Chat history), add 'Human: Let's get started.'." placeholder="Your message, instruction, etc... WHEN EMPTY and no manually added Human's message found between sysprompt and the first assistant message(Chat history), add 'Human: Let's get started.'."></textarea>
|
||||
<div class="range-block-title openai_restorable">
|
||||
<span id="claude_human_sysprompt_textarea_text" data-i18n="Human: first message">Human: first message</span>
|
||||
<div id="claude_human_sysprompt_message_restore" title="Restore Human: first message" class="right_menu_button">
|
||||
<div class="fa-solid fa-clock-rotate-left"></div>
|
||||
</div>
|
||||
</div>
|
||||
<textarea id="claude_human_sysprompt_textarea" class="text_pole textarea_compact" name="human_sysprompt_message autoSetHeight" rows="3" maxlength="10000" data-i18n="[placeholder]Your(Human: ) message, instruction, etc... !!WHEN EMPTY, ADDS NOTHING!!I.e., requires a new prompt with the role 'user' or manually adding the 'Human: ' prefix." placeholder="Your(Human: ) message, instruction, etc... !!WHEN EMPTY, ADDS NOTHING!! I.e., requires a new prompt with the role 'user' or manually adding the 'Human: ' prefix."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -90,6 +90,7 @@ const default_wi_format = '[Details of the fictional world the RP is set in:\n{0
|
||||
const default_new_chat_prompt = '[Start a new Chat]';
|
||||
const default_new_group_chat_prompt = '[Start a new group chat. Group members: {{group}}]';
|
||||
const default_new_example_chat_prompt = '[Start a new Chat]';
|
||||
const default_claude_human_sysprompt_message = 'Let\'s get started. Please generate your response based on the information and instructions provided above.';
|
||||
const default_continue_nudge_prompt = '[Continue the following message. Do not include ANY parts of the original message. Use capitalization and punctuation as if your reply is a part of the original message: {{lastChatMessage}}]';
|
||||
const default_bias = 'Default (none)';
|
||||
const default_personality_format = '[{{char}}\'s personality: {{personality}}]';
|
||||
@ -224,7 +225,7 @@ const default_settings = {
|
||||
show_external_models: false,
|
||||
proxy_password: '',
|
||||
assistant_prefill: '',
|
||||
human_sysprompt_message: '',
|
||||
human_sysprompt_message: default_claude_human_sysprompt_message,
|
||||
use_ai21_tokenizer: false,
|
||||
use_google_tokenizer: false,
|
||||
exclude_assistant: false,
|
||||
@ -282,7 +283,7 @@ const oai_settings = {
|
||||
show_external_models: false,
|
||||
proxy_password: '',
|
||||
assistant_prefill: '',
|
||||
human_sysprompt_message: '',
|
||||
human_sysprompt_message: default_claude_human_sysprompt_message,
|
||||
use_ai21_tokenizer: false,
|
||||
use_google_tokenizer: false,
|
||||
exclude_assistant: false,
|
||||
@ -2348,7 +2349,7 @@ function loadOpenAISettings(data, settings) {
|
||||
$('#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_message').val(oai_settings.human_sysprompt_message);
|
||||
$('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message);
|
||||
$('#openai_image_inlining').prop('checked', oai_settings.image_inlining);
|
||||
$('#openai_bypass_status_check').prop('checked', oai_settings.bypass_status_check);
|
||||
|
||||
@ -2941,7 +2942,7 @@ function onSettingsPresetChange() {
|
||||
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_message', 'human_sysprompt_message', false],
|
||||
human_sysprompt_message: ['#claude_human_sysprompt_textarea', 'human_sysprompt_message', false],
|
||||
use_ai21_tokenizer: ['#use_ai21_tokenizer', 'use_ai21_tokenizer', true],
|
||||
use_google_tokenizer: ['#use_google_tokenizer', 'use_google_tokenizer', true],
|
||||
exclude_assistant: ['#exclude_assistant', 'exclude_assistant', true],
|
||||
@ -3679,6 +3680,12 @@ $(document).ready(async function () {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#claude_human_sysprompt_message_restore').on('click', function () {
|
||||
oai_settings.human_sysprompt_message = default_claude_human_sysprompt_message;
|
||||
$('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#newgroupchat_prompt_restore').on('click', function () {
|
||||
oai_settings.new_group_chat_prompt = default_new_group_chat_prompt;
|
||||
$('#newgroupchat_prompt_textarea').val(oai_settings.new_group_chat_prompt);
|
||||
@ -3766,8 +3773,8 @@ $(document).ready(async function () {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#claude_human_sysprompt_message').on('input', function () {
|
||||
oai_settings.human_sysprompt_message = String($(this).val());
|
||||
$('#claude_human_sysprompt_textarea').on('input', function () {
|
||||
oai_settings.human_sysprompt_message = String($('#claude_human_sysprompt_textarea').val());
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
|
@ -60,13 +60,20 @@ async function sendClaudeRequest(request, response) {
|
||||
}
|
||||
|
||||
if (!humanFound) {
|
||||
console.log(chalk.red(`${divider}\nWarning: No Human prefix found in the prompt.\n${divider}`));
|
||||
console.log(chalk.red(`${divider}\nWarning: No 'Human:' prefix found in the prompt.\n${divider}`));
|
||||
}
|
||||
if (!assistantFound) {
|
||||
console.log(chalk.red(`${divider}\nWarning: No Assistant prefix found in the prompt.\n${divider}`));
|
||||
console.log(chalk.red(`${divider}\nWarning: No 'Assistant: ' prefix found in the prompt.\n${divider}`));
|
||||
}
|
||||
if (!sequence[0].startsWith('Human:')) {
|
||||
console.log(chalk.red(`${divider}\nWarning: The messages sequence should start with 'Human:' prefix.\nMake sure you have 'Human:' prefix at the very beggining of the prompt, or after the system prompt.\n${divider}`));
|
||||
}
|
||||
if (humanErrorCount > 0 || assistantErrorCount > 0) {
|
||||
console.log(chalk.red(`${divider}\nWarning: Detected incorrect Prefix sequence(s).\nIncorrect 'Human:' prefix(es): ${humanErrorCount}.\nIncorrect 'Assistant:' prefix(es): ${assistantErrorCount}.\nCheck the prompt above and fix it in the sillytavern.\nThe correct sequence should look like this:\nSystem prompt message <--(for new sysprompt format only)\n <------------------(Every message start with Assistant:/Human:prefix should have one empty line above)\nHuman:\n\nAssistant:\n\...\n\nHuman:\n\nAssistant:\n${divider}`));
|
||||
console.log(chalk.red(`${divider}\nWarning: Detected incorrect Prefix sequence(s).`));
|
||||
console.log(chalk.red(`Incorrect "Human:" prefix(es): ${humanErrorCount}.\nIncorrect "Assistant: " prefix(es): ${assistantErrorCount}.`));
|
||||
console.log(chalk.red('Check the prompt above and fix it in the sillytavern.'));
|
||||
console.log(chalk.red('\nThe correct sequence should look like this:\nSystem prompt <-(for the sysprompt format only, else have 2 empty lines above the first human\'s message.)'));
|
||||
console.log(chalk.red(` <-----(Each message beginning with the "Assistant:/Human:" prefix must have one empty line above.)\nHuman:\n\nAssistant:\n...\n\nHuman:\n\nAssistant:\n${divider}`));
|
||||
}
|
||||
const stop_sequences = ['\n\nHuman:', '\n\nSystem:', '\n\nAssistant:'];
|
||||
|
||||
|
@ -24,12 +24,8 @@ function convertClaudePrompt(messages, addAssistantPostfix, addAssistantPrefill,
|
||||
}
|
||||
// Find the index of the first message with an assistant role and check for a "'user' role/Human:" before it.
|
||||
let hasUser = false;
|
||||
let hasAssist = false;
|
||||
const firstAssistantIndex = messages.findIndex((message, i) => {
|
||||
if (i >= 0 && (message.role === 'user' || message.content.includes('\n\nHuman: '))) {
|
||||
if (message.content.includes('\n\nAssistant: ')) {
|
||||
hasAssist = true;
|
||||
}
|
||||
hasUser = true;
|
||||
}
|
||||
return message.role === 'assistant' && i > 0;
|
||||
@ -38,10 +34,10 @@ function convertClaudePrompt(messages, addAssistantPostfix, addAssistantPrefill,
|
||||
// Inserts the human's message before the first the assistant one, if there are no such message or prefix found.
|
||||
if (withSyspromptSupport && useSystemPrompt) {
|
||||
messages[0].role = 'system';
|
||||
if (firstAssistantIndex > 0 && (!hasUser || (hasUser && hasAssist))) { //addSysHumanMsg for test
|
||||
if (firstAssistantIndex > 0 && addSysHumanMsg && !hasUser) {
|
||||
messages.splice(firstAssistantIndex, 0, {
|
||||
role: 'user',
|
||||
content: addSysHumanMsg || 'Let\'s get started.',
|
||||
content: addSysHumanMsg,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -58,20 +54,15 @@ function convertClaudePrompt(messages, addAssistantPostfix, addAssistantPrefill,
|
||||
|
||||
// Convert messages to requestPrompt.
|
||||
let requestPrompt = messages.map((v, i) => {
|
||||
// Claude doesn't support message names, so we'll just add them to the message content.
|
||||
if (v.name && v.role !== 'system') {
|
||||
v.content = `${v.name}: ${v.content}`;
|
||||
delete v.name;
|
||||
}
|
||||
//let prefix = ''; // Set prefix according to the role.
|
||||
// Set prefix according to the role.
|
||||
let prefix = {
|
||||
'assistant': '\n\nAssistant: ',
|
||||
'user': '\n\nHuman: ',
|
||||
'system': i === 0 ? '' : v.name === 'example_assistant' ? '\n\nA: ' : v.name === 'example_user' ? '\n\nH: ' : '\n\n',
|
||||
'FixHumMsg': '\n\nFirst message: ',
|
||||
}[v.role] ?? '\n\n';
|
||||
|
||||
return prefix + v.content;
|
||||
}[v.role] ?? '';
|
||||
// Claude doesn't support message names, so we'll just add them to the message content.
|
||||
return `${prefix}${v.name && v.role !== 'system' ? `${v.name}: ` : ''}${v.content}`;
|
||||
}).join('');
|
||||
|
||||
return requestPrompt;
|
||||
|
Loading…
x
Reference in New Issue
Block a user