From a012fcaaae95ac5b5f79de4d61b4ae83d76d1268 Mon Sep 17 00:00:00 2001 From: pelikhan Date: Thu, 19 Dec 2024 05:22:09 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20handle=20array=20content=20?= =?UTF-8?q?in=20message=20append=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/chat.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/src/chat.ts b/packages/core/src/chat.ts index eec013baf..7aa453aad 100644 --- a/packages/core/src/chat.ts +++ b/packages/core/src/chat.ts @@ -1085,8 +1085,10 @@ export function appendUserMessage( if (ephemeral) last.cacheControl = "ephemeral" messages.push(last) } - if (last.content) last.content += "\n" + content - else last.content = content + if (last.content) { + if (typeof last.content === "string") last.content += "\n" + content + else last.content.push({ type: "text", text: content }) + } else last.content = content } export function appendAssistantMessage( @@ -1108,8 +1110,10 @@ export function appendAssistantMessage( if (ephemeral) last.cacheControl = "ephemeral" messages.push(last) } - if (last.content) last.content += "\n" + content - else last.content = content + if (last.content) { + if (typeof last.content === "string") last.content += "\n" + content + else last.content.push({ type: "text", text: content }) + } else last.content = content } export function appendSystemMessage( @@ -1132,8 +1136,11 @@ export function appendSystemMessage( if (ephemeral) last.cacheControl = "ephemeral" messages.unshift(last) } - if (last.content) last.content += SYSTEM_FENCE - last.content += content + if (last.content) { + if (typeof last.content === "string") + last.content += SYSTEM_FENCE + content + else last.content.push({ type: "text", text: content }) + } else last.content = content } export function addToolDefinitionsMessage(