From 06510f25bf4945b90e1d8703318ef3ee20e5bfed Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:37:28 +0200 Subject: [PATCH] Fix double append of example dialogue names in group chats for Claude --- src/prompt-converters.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index 0b5af8f80..42f7abaf7 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -89,11 +89,16 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi if (messages[i].role !== 'system') { break; } + // Append example names if not already done by the frontend (e.g. for group chats). if (userName && messages[i].name === 'example_user') { - messages[i].content = `${userName}: ${messages[i].content}`; + if (!messages[i].content.startsWith(`${userName}: `)) { + messages[i].content = `${userName}: ${messages[i].content}`; + } } if (charName && messages[i].name === 'example_assistant') { - messages[i].content = `${charName}: ${messages[i].content}`; + if (!messages[i].content.startsWith(`${charName}: `)) { + messages[i].content = `${charName}: ${messages[i].content}`; + } } systemPrompt += `${messages[i].content}\n\n`; }