Pass char/user names for Claude example messages converter
This commit is contained in:
parent
e9d0c5bb05
commit
15eb18740e
|
@ -1603,6 +1603,8 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||
'stop': getCustomStoppingStrings(openai_max_stop_strings),
|
||||
'chat_completion_source': oai_settings.chat_completion_source,
|
||||
'n': canMultiSwipe ? oai_settings.n : undefined,
|
||||
'user_name': name1,
|
||||
'char_name': name2,
|
||||
};
|
||||
|
||||
// Empty array will produce a validation error
|
||||
|
|
|
@ -35,7 +35,7 @@ async function sendClaudeRequest(request, response) {
|
|||
controller.abort();
|
||||
});
|
||||
let use_system_prompt = (request.body.model.startsWith('claude-2') || request.body.model.startsWith('claude-3')) && request.body.claude_use_sysprompt;
|
||||
let converted_prompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, use_system_prompt, request.body.human_sysprompt_message);
|
||||
let converted_prompt = convertClaudeMessages(request.body.messages, request.body.assistant_prefill, use_system_prompt, request.body.human_sysprompt_message, request.body.char_name, request.body.user_name);
|
||||
// Add custom stop sequences
|
||||
const stopSequences = ['\n\nHuman:', '\n\nSystem:', '\n\nAssistant:'];
|
||||
if (Array.isArray(request.body.stop)) {
|
||||
|
|
|
@ -77,8 +77,10 @@ function convertClaudePrompt(messages, addAssistantPostfix, addAssistantPrefill,
|
|||
* @param {string} prefillString User determined prefill string
|
||||
* @param {boolean} useSysPrompt See if we want to use a system prompt
|
||||
* @param {string} humanMsgFix Add Human message between system prompt and assistant.
|
||||
* @param {string} charName Character name
|
||||
* @param {string} userName User name
|
||||
*/
|
||||
function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFix) {
|
||||
function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFix, charName = '', userName = '') {
|
||||
let systemPrompt = '';
|
||||
if (useSysPrompt) {
|
||||
// Collect all the system messages up until the first instance of a non-system message, and then remove them from the messages array.
|
||||
|
@ -87,6 +89,12 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
|
|||
if (messages[i].role !== 'system') {
|
||||
break;
|
||||
}
|
||||
if (userName && messages[i].name === 'example_user') {
|
||||
messages[i].content = `${userName}: ${messages[i].content}`;
|
||||
}
|
||||
if (charName && messages[i].name === 'example_assistant') {
|
||||
messages[i].content = `${charName}: ${messages[i].content}`;
|
||||
}
|
||||
systemPrompt += `${messages[i].content}\n\n`;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue