Claude: remove user filler from prompt converter
| @@ -230,7 +230,6 @@ | |||
| 230 | "show_external_models": false, | 230 | "show_external_models": false, |
| 231 | "assistant_prefill": "", | 231 | "assistant_prefill": "", |
| 232 | "assistant_impersonation": "", | 232 | "assistant_impersonation": "", |
| 233 | "human_sysprompt_message": "Let's get started. Please generate your response based on the information and instructions provided above.", | ||
| 234 | "claude_use_sysprompt": false, | 233 | "claude_use_sysprompt": false, |
| 235 | "use_alt_scale": false, | 234 | "use_alt_scale": false, |
| 236 | "squash_system_messages": false, | 235 | "squash_system_messages": false, |
| @@ -1951,15 +1951,6 @@ | |||
| 1951 | Send the system prompt for supported models. If disabled, the user message is added to the beginning of the prompt. | 1951 | Send the system prompt for supported models. If disabled, the user message is added to the beginning of the prompt. |
| 1952 | </span> | 1952 | </span> |
| 1953 | </div> | 1953 | </div> |
| 1954 | <div id="claude_human_sysprompt_message_block" class="wide100p"> | ||
| 1955 | <div class="range-block-title openai_restorable"> | ||
| 1956 | <span data-i18n="User first message">User first message</span> | ||
| 1957 | <div id="claude_human_sysprompt_message_restore" title="Restore User first message" data-i18n="[title]Restore User first message" class="right_menu_button"> | ||
| 1958 | <div class="fa-solid fa-clock-rotate-left"></div> | ||
| 1959 | </div> | ||
| 1960 | </div> | ||
| 1961 | <textarea id="claude_human_sysprompt_textarea" class="text_pole textarea_compact autoSetHeight" rows="2" data-i18n="[placeholder]Human message" placeholder="Human message, instruction, etc. Adds nothing when empty, i.e. requires a new prompt with the role 'user'."></textarea> | ||
| 1962 | </div> | ||
| 1963 | </div> | 1954 | </div> |
| 1964 | </div> | 1955 | </div> |
| 1965 | <div class="range-block m-t-1" data-source="openai,openrouter,scale,custom"> | 1956 | <div class="range-block m-t-1" data-source="openai,openrouter,scale,custom"> |
| @@ -99,7 +99,6 @@ const default_wi_format = '{0}'; | |||
| 99 | const default_new_chat_prompt = '[Start a new Chat]'; | 99 | const default_new_chat_prompt = '[Start a new Chat]'; |
| 100 | const default_new_group_chat_prompt = '[Start a new group chat. Group members: {{group}}]'; | 100 | const default_new_group_chat_prompt = '[Start a new group chat. Group members: {{group}}]'; |
| 101 | const default_new_example_chat_prompt = '[Example Chat]'; | 101 | const default_new_example_chat_prompt = '[Example Chat]'; |
| 102 | const default_claude_human_sysprompt_message = 'Let\'s get started. Please generate your response based on the information and instructions provided above.'; | ||
| 103 | 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}}]'; | 102 | 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}}]'; |
| 104 | const default_bias = 'Default (none)'; | 103 | const default_bias = 'Default (none)'; |
| 105 | const default_personality_format = '[{{char}}\'s personality: {{personality}}]'; | 104 | const default_personality_format = '[{{char}}\'s personality: {{personality}}]'; |
| @@ -276,7 +275,6 @@ const default_settings = { | |||
| 276 | proxy_password: '', | 275 | proxy_password: '', |
| 277 | assistant_prefill: '', | 276 | assistant_prefill: '', |
| 278 | assistant_impersonation: '', | 277 | assistant_impersonation: '', |
| 279 | human_sysprompt_message: default_claude_human_sysprompt_message, | ||
| 280 | claude_use_sysprompt: false, | 278 | claude_use_sysprompt: false, |
| 281 | use_makersuite_sysprompt: true, | 279 | use_makersuite_sysprompt: true, |
| 282 | use_alt_scale: false, | 280 | use_alt_scale: false, |
| @@ -353,7 +351,6 @@ const oai_settings = { | |||
| 353 | proxy_password: '', | 351 | proxy_password: '', |
| 354 | assistant_prefill: '', | 352 | assistant_prefill: '', |
| 355 | assistant_impersonation: '', | 353 | assistant_impersonation: '', |
| 356 | human_sysprompt_message: default_claude_human_sysprompt_message, | ||
| 357 | claude_use_sysprompt: false, | 354 | claude_use_sysprompt: false, |
| 358 | use_makersuite_sysprompt: true, | 355 | use_makersuite_sysprompt: true, |
| 359 | use_alt_scale: false, | 356 | use_alt_scale: false, |
| @@ -1892,7 +1889,6 @@ async function sendOpenAIRequest(type, messages, signal) { | |||
| 1892 | generate_data['top_k'] = Number(oai_settings.top_k_openai); | 1889 | generate_data['top_k'] = Number(oai_settings.top_k_openai); |
| 1893 | generate_data['claude_use_sysprompt'] = oai_settings.claude_use_sysprompt; | 1890 | generate_data['claude_use_sysprompt'] = oai_settings.claude_use_sysprompt; |
| 1894 | generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings. | 1891 | generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings. |
| 1895 | generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message); | ||
| 1896 | // Don't add a prefill on quiet gens (summarization) and when using continue prefill. | 1892 | // Don't add a prefill on quiet gens (summarization) and when using continue prefill. |
| 1897 | if (!isQuiet && !(isContinue && oai_settings.continue_prefill)) { | 1893 | if (!isQuiet && !(isContinue && oai_settings.continue_prefill)) { |
| 1898 | generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill); | 1894 | generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill); |
| @@ -3030,7 +3026,6 @@ function loadOpenAISettings(data, settings) { | |||
| 3030 | oai_settings.proxy_password = settings.proxy_password ?? default_settings.proxy_password; | 3026 | oai_settings.proxy_password = settings.proxy_password ?? default_settings.proxy_password; |
| 3031 | oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill; | 3027 | oai_settings.assistant_prefill = settings.assistant_prefill ?? default_settings.assistant_prefill; |
| 3032 | oai_settings.assistant_impersonation = settings.assistant_impersonation ?? default_settings.assistant_impersonation; | 3028 | oai_settings.assistant_impersonation = settings.assistant_impersonation ?? default_settings.assistant_impersonation; |
| 3033 | oai_settings.human_sysprompt_message = settings.human_sysprompt_message ?? default_settings.human_sysprompt_message; | ||
| 3034 | oai_settings.image_inlining = settings.image_inlining ?? default_settings.image_inlining; | 3029 | oai_settings.image_inlining = settings.image_inlining ?? default_settings.image_inlining; |
| 3035 | oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality; | 3030 | oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality; |
| 3036 | oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check; | 3031 | oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check; |
| @@ -3070,7 +3065,6 @@ function loadOpenAISettings(data, settings) { | |||
| 3070 | $('#openai_proxy_password').val(oai_settings.proxy_password); | 3065 | $('#openai_proxy_password').val(oai_settings.proxy_password); |
| 3071 | $('#claude_assistant_prefill').val(oai_settings.assistant_prefill); | 3066 | $('#claude_assistant_prefill').val(oai_settings.assistant_prefill); |
| 3072 | $('#claude_assistant_impersonation').val(oai_settings.assistant_impersonation); | 3067 | $('#claude_assistant_impersonation').val(oai_settings.assistant_impersonation); |
| 3073 | $('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message); | ||
| 3074 | $('#openai_image_inlining').prop('checked', oai_settings.image_inlining); | 3068 | $('#openai_image_inlining').prop('checked', oai_settings.image_inlining); |
| 3075 | $('#openai_bypass_status_check').prop('checked', oai_settings.bypass_status_check); | 3069 | $('#openai_bypass_status_check').prop('checked', oai_settings.bypass_status_check); |
| 3076 | 3070 | ||
| @@ -3400,7 +3394,6 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) { | |||
| 3400 | show_external_models: settings.show_external_models, | 3394 | show_external_models: settings.show_external_models, |
| 3401 | assistant_prefill: settings.assistant_prefill, | 3395 | assistant_prefill: settings.assistant_prefill, |
| 3402 | assistant_impersonation: settings.assistant_impersonation, | 3396 | assistant_impersonation: settings.assistant_impersonation, |
| 3403 | human_sysprompt_message: settings.human_sysprompt_message, | ||
| 3404 | claude_use_sysprompt: settings.claude_use_sysprompt, | 3397 | claude_use_sysprompt: settings.claude_use_sysprompt, |
| 3405 | use_makersuite_sysprompt: settings.use_makersuite_sysprompt, | 3398 | use_makersuite_sysprompt: settings.use_makersuite_sysprompt, |
| 3406 | use_alt_scale: settings.use_alt_scale, | 3399 | use_alt_scale: settings.use_alt_scale, |
| @@ -3825,7 +3818,6 @@ function onSettingsPresetChange() { | |||
| 3825 | proxy_password: ['#openai_proxy_password', 'proxy_password', false], | 3818 | proxy_password: ['#openai_proxy_password', 'proxy_password', false], |
| 3826 | assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false], | 3819 | assistant_prefill: ['#claude_assistant_prefill', 'assistant_prefill', false], |
| 3827 | assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false], | 3820 | assistant_impersonation: ['#claude_assistant_impersonation', 'assistant_impersonation', false], |
| 3828 | human_sysprompt_message: ['#claude_human_sysprompt_textarea', 'human_sysprompt_message', false], | ||
| 3829 | claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true], | 3821 | claude_use_sysprompt: ['#claude_use_sysprompt', 'claude_use_sysprompt', true], |
| 3830 | use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true], | 3822 | use_makersuite_sysprompt: ['#use_makersuite_sysprompt', 'use_makersuite_sysprompt', true], |
| 3831 | use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true], | 3823 | use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true], |
| @@ -4677,10 +4669,6 @@ function toggleChatCompletionForms() { | |||
| 4677 | const validSources = $(this).data('source').split(','); | 4669 | const validSources = $(this).data('source').split(','); |
| 4678 | $(this).toggle(validSources.includes(oai_settings.chat_completion_source)); | 4670 | $(this).toggle(validSources.includes(oai_settings.chat_completion_source)); |
| 4679 | }); | 4671 | }); |
| 4680 | |||
| 4681 | if (chat_completion_sources.CLAUDE == oai_settings.chat_completion_source) { | ||
| 4682 | $('#claude_human_sysprompt_message_block').toggle(oai_settings.claude_use_sysprompt); | ||
| 4683 | } | ||
| 4684 | } | 4672 | } |
| 4685 | 4673 | ||
| 4686 | async function testApiConnection() { | 4674 | async function testApiConnection() { |
| @@ -5036,7 +5024,6 @@ export function initOpenAI() { | |||
| 5036 | 5024 | ||
| 5037 | $('#claude_use_sysprompt').on('change', function () { | 5025 | $('#claude_use_sysprompt').on('change', function () { |
| 5038 | oai_settings.claude_use_sysprompt = !!$('#claude_use_sysprompt').prop('checked'); | 5026 | oai_settings.claude_use_sysprompt = !!$('#claude_use_sysprompt').prop('checked'); |
| 5039 | $('#claude_human_sysprompt_message_block').toggle(oai_settings.claude_use_sysprompt); | ||
| 5040 | saveSettingsDebounced(); | 5027 | saveSettingsDebounced(); |
| 5041 | }); | 5028 | }); |
| 5042 | 5029 | ||
| @@ -5113,12 +5100,6 @@ export function initOpenAI() { | |||
| 5113 | saveSettingsDebounced(); | 5100 | saveSettingsDebounced(); |
| 5114 | }); | 5101 | }); |
| 5115 | 5102 | ||
| 5116 | $('#claude_human_sysprompt_message_restore').on('click', function () { | ||
| 5117 | oai_settings.human_sysprompt_message = default_claude_human_sysprompt_message; | ||
| 5118 | $('#claude_human_sysprompt_textarea').val(oai_settings.human_sysprompt_message); | ||
| 5119 | saveSettingsDebounced(); | ||
| 5120 | }); | ||
| 5121 | |||
| 5122 | $('#newgroupchat_prompt_restore').on('click', function () { | 5103 | $('#newgroupchat_prompt_restore').on('click', function () { |
| 5123 | oai_settings.new_group_chat_prompt = default_new_group_chat_prompt; | 5104 | oai_settings.new_group_chat_prompt = default_new_group_chat_prompt; |
| 5124 | $('#newgroupchat_prompt_textarea').val(oai_settings.new_group_chat_prompt); | 5105 | $('#newgroupchat_prompt_textarea').val(oai_settings.new_group_chat_prompt); |
| @@ -5210,11 +5191,6 @@ export function initOpenAI() { | |||
| 5210 | saveSettingsDebounced(); | 5191 | saveSettingsDebounced(); |
| 5211 | }); | 5192 | }); |
| 5212 | 5193 | ||
| 5213 | $('#claude_human_sysprompt_textarea').on('input', function () { | ||
| 5214 | oai_settings.human_sysprompt_message = String($('#claude_human_sysprompt_textarea').val()); | ||
| 5215 | saveSettingsDebounced(); | ||
| 5216 | }); | ||
| 5217 | |||
| 5218 | $('#openrouter_use_fallback').on('input', function () { | 5194 | $('#openrouter_use_fallback').on('input', function () { |
| 5219 | oai_settings.openrouter_use_fallback = !!$(this).prop('checked'); | 5195 | oai_settings.openrouter_use_fallback = !!$(this).prop('checked'); |
| 5220 | saveSettingsDebounced(); | 5196 | saveSettingsDebounced(); |
| @@ -102,7 +102,7 @@ async function sendClaudeRequest(request, response) { | |||
| 102 | const additionalHeaders = {}; | 102 | const additionalHeaders = {}; |
| 103 | const useTools = request.body.model.startsWith('claude-3') && Array.isArray(request.body.tools) && request.body.tools.length > 0; | 103 | const useTools = request.body.model.startsWith('claude-3') && Array.isArray(request.body.tools) && request.body.tools.length > 0; |
| 104 | const useSystemPrompt = (request.body.model.startsWith('claude-2') || request.body.model.startsWith('claude-3')) && request.body.claude_use_sysprompt; | 104 | const useSystemPrompt = (request.body.model.startsWith('claude-2') || request.body.model.startsWith('claude-3')) && request.body.claude_use_sysprompt; |
| 105 | const convertedPrompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, useSystemPrompt, useTools, request.body.human_sysprompt_message, request.body.char_name, request.body.user_name); | 105 | const convertedPrompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, useSystemPrompt, useTools, request.body.char_name, request.body.user_name); |
| 106 | // Add custom stop sequences | 106 | // Add custom stop sequences |
| 107 | const stopSequences = []; | 107 | const stopSequences = []; |
| 108 | if (Array.isArray(request.body.stop)) { | 108 | if (Array.isArray(request.body.stop)) { |
| @@ -91,11 +91,10 @@ export function convertClaudePrompt(messages, addAssistantPostfix, addAssistantP | |||
| 91 | * @param {string} prefillString User determined prefill string | 91 | * @param {string} prefillString User determined prefill string |
| 92 | * @param {boolean} useSysPrompt See if we want to use a system prompt | 92 | * @param {boolean} useSysPrompt See if we want to use a system prompt |
| 93 | * @param {boolean} useTools See if we want to use tools | 93 | * @param {boolean} useTools See if we want to use tools |
| 94 | * @param {string} humanMsgFix Add Human message between system prompt and assistant. | ||
| 95 | * @param {string} charName Character name | 94 | * @param {string} charName Character name |
| 96 | * @param {string} userName User name | 95 | * @param {string} userName User name |
| 97 | */ | 96 | */ |
| 98 | export function convertClaudeMessages(messages, prefillString, useSysPrompt, useTools, humanMsgFix, charName = '', userName = '') { | 97 | export function convertClaudeMessages(messages, prefillString, useSysPrompt, useTools, charName, userName) { |
| 99 | let systemPrompt = []; | 98 | let systemPrompt = []; |
| 100 | if (useSysPrompt) { | 99 | if (useSysPrompt) { |
| 101 | // Collect all the system messages up until the first instance of a non-system message, and then remove them from the messages array. | 100 | // Collect all the system messages up until the first instance of a non-system message, and then remove them from the messages array. |
| @@ -122,10 +121,10 @@ export function convertClaudeMessages(messages, prefillString, useSysPrompt, use | |||
| 122 | 121 | ||
| 123 | // Check if the first message in the array is of type user, if not, interject with humanMsgFix or a blank message. | 122 | // Check if the first message in the array is of type user, if not, interject with humanMsgFix or a blank message. |
| 124 | // Also prevents erroring out if the messages array is empty. | 123 | // Also prevents erroring out if the messages array is empty. |
| 125 | if (messages.length === 0 || (messages.length > 0 && messages[0].role !== 'user')) { | 124 | if (messages.length === 0) { |
| 126 | messages.unshift({ | 125 | messages.unshift({ |
| 127 | role: 'user', | 126 | role: 'user', |
| 128 | content: humanMsgFix || PROMPT_PLACEHOLDER, | 127 | content: PROMPT_PLACEHOLDER, |
| 129 | }); | 128 | }); |
| 130 | } | 129 | } |
| 131 | } | 130 | } |