mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-07 07:06:05 +01:00
Fix names in completions not getting added when squashing assistant messages
This commit is contained in:
parent
9f0c2e0ddb
commit
5d561b64e2
@ -125,20 +125,30 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
|
|||||||
// Also handle multi-modality, holy slop.
|
// Also handle multi-modality, holy slop.
|
||||||
let mergedMessages = [];
|
let mergedMessages = [];
|
||||||
messages.forEach((message) => {
|
messages.forEach((message) => {
|
||||||
const imageEntry = message.content[1]?.image_url;
|
const imageEntry = message.content?.[1]?.image_url;
|
||||||
const imageData = imageEntry?.url;
|
const imageData = imageEntry?.url;
|
||||||
const mimeType = imageData?.split(';')[0].split(':')[1];
|
const mimeType = imageData?.split(';')?.[0].split(':')?.[1];
|
||||||
const base64Data = imageData?.split(',')[1];
|
const base64Data = imageData?.split(',')?.[1];
|
||||||
|
|
||||||
|
// Take care of name properties since claude messages don't support them
|
||||||
|
if (message.name) {
|
||||||
|
if (Array.isArray(message.content)) {
|
||||||
|
message.content[0].text = `${message.name}: ${message.content[0].text}`;
|
||||||
|
} else {
|
||||||
|
message.content = `${message.name}: ${message.content}`;
|
||||||
|
}
|
||||||
|
delete message.name;
|
||||||
|
}
|
||||||
|
|
||||||
if (mergedMessages.length > 0 && mergedMessages[mergedMessages.length - 1].role === message.role) {
|
if (mergedMessages.length > 0 && mergedMessages[mergedMessages.length - 1].role === message.role) {
|
||||||
if(Array.isArray(message.content)) {
|
if (Array.isArray(message.content)) {
|
||||||
if(Array.isArray(mergedMessages[mergedMessages.length - 1].content)) {
|
if (Array.isArray(mergedMessages[mergedMessages.length - 1].content)) {
|
||||||
mergedMessages[mergedMessages.length - 1].content[0].text += '\n\n' + message.content[0].text;
|
mergedMessages[mergedMessages.length - 1].content[0].text += '\n\n' + message.content[0].text;
|
||||||
} else {
|
} else {
|
||||||
mergedMessages[mergedMessages.length - 1].content += '\n\n' + message.content[0].text;
|
mergedMessages[mergedMessages.length - 1].content += '\n\n' + message.content[0].text;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(Array.isArray(mergedMessages[mergedMessages.length - 1].content)) {
|
if (Array.isArray(mergedMessages[mergedMessages.length - 1].content)) {
|
||||||
mergedMessages[mergedMessages.length - 1].content[0].text += '\n\n' + message.content;
|
mergedMessages[mergedMessages.length - 1].content[0].text += '\n\n' + message.content;
|
||||||
} else {
|
} else {
|
||||||
mergedMessages[mergedMessages.length - 1].content += '\n\n' + message.content;
|
mergedMessages[mergedMessages.length - 1].content += '\n\n' + message.content;
|
||||||
@ -161,19 +171,6 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Take care of name properties since claude messages don't support them
|
|
||||||
mergedMessages.forEach((message) => {
|
|
||||||
if (message.name) {
|
|
||||||
if (Array.isArray(message.content)) {
|
|
||||||
message.content[0].text = `${message.name}: ${message.content[0].text}`;
|
|
||||||
} else {
|
|
||||||
message.content = `${message.name}: ${message.content}`;
|
|
||||||
}
|
|
||||||
delete message.name;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling
|
// Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling
|
||||||
if (prefillString) {
|
if (prefillString) {
|
||||||
mergedMessages.push({
|
mergedMessages.push({
|
||||||
|
Loading…
Reference in New Issue
Block a user