From e17d55b9eacfba1891430ee5216a2960ab024586 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 20 Dec 2024 02:03:04 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8F=97=EF=B8=8F=20add=20check=20f?= =?UTF-8?q?or=20undefined=20text=20in=20tracePromptResult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/chat.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/core/src/chat.ts b/packages/core/src/chat.ts index c49ad0455..f39d7e7ed 100644 --- a/packages/core/src/chat.ts +++ b/packages/core/src/chat.ts @@ -1052,18 +1052,20 @@ export function tracePromptResult( const { text } = resp || {} // try to sniff the output type - const language = JSON5TryParse(text) - ? "json" - : XMLTryParse(text) - ? "xml" - : /^(-|\*|#+|```)\s/im.test(text) - ? "markdown" - : "text" - trace.detailsFenced(`🔠 output`, text, language) - if (language === "markdown") - trace.appendContent( - "\n\n" + HTMLEscape(prettifyMarkdown(text)) + "\n\n" - ) + if (text !== undefined) { + const language = JSON5TryParse(text) + ? "json" + : XMLTryParse(text) + ? "xml" + : /^(-|\*|#+|```)\s/im.test(text) + ? "markdown" + : "text" + trace.detailsFenced(`🔠 output`, text, language) + if (language === "markdown") + trace.appendContent( + "\n\n" + HTMLEscape(prettifyMarkdown(text)) + "\n\n" + ) + } } export function appendUserMessage(