From 3d75fb4a2b296f87f2ecbac763bb3e4339a6f307 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 18 Dec 2024 21:19:49 -0800 Subject: [PATCH] fix prompt logs for tools --- core/llm/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index c5a0d5c79..70fafda53 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -445,11 +445,22 @@ export abstract class BaseLLM implements ILLM { const msgsCopy = messages ? messages.map((msg) => ({ ...msg })) : []; let formatted = ""; for (const msg of msgsCopy) { - if ("content" in msg && Array.isArray(msg.content)) { + let contentToShow = ""; + if (msg.role === "tool") { + contentToShow = msg.content; + } else if (msg.role === "assistant" && msg.toolCalls) { + contentToShow = msg.toolCalls + ?.map( + (toolCall) => + `${toolCall.function?.name}(${toolCall.function?.arguments})`, + ) + .join("\n"); + } else if ("content" in msg && Array.isArray(msg.content)) { const content = renderChatMessage(msg); msg.content = content; } - formatted += `<${msg.role}>\n${msg.content || ""}\n\n`; + + formatted += `<${msg.role}>\n${contentToShow}\n\n`; } return formatted; }