From 9c7b36fa7e8c552b446ec43e38cbf3ce632e2201 Mon Sep 17 00:00:00 2001 From: Ian Arawjo Date: Wed, 18 Oct 2023 14:30:44 -0400 Subject: [PATCH] Bug fix chat histories with undefined content in messages --- chainforge/react-server/src/PromptNode.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chainforge/react-server/src/PromptNode.js b/chainforge/react-server/src/PromptNode.js index 592f73c..0ad13ab 100644 --- a/chainforge/react-server/src/PromptNode.js +++ b/chainforge/react-server/src/PromptNode.js @@ -399,6 +399,20 @@ const PromptNode = ({ data, id, type: node_type }) => { return; } + // Check if pulled chats includes undefined content. + // This could happen with Join nodes, where there is no longer a single "prompt" (user prompt) + // of the chat provenance. Instead of blocking this behavior, we replace undefined with a blank string, + // and output a warning to the console. + if (!pulled_chats.every(c => c.messages.every(m => m.content !== undefined))) { + console.warn("Chat history contains undefined content. This can happen if a Join Node was used, \ + as there is no longer a single prompt as the provenance of the conversation. \ + Soft failing by replacing undefined with empty strings."); + pulled_chats.forEach(c => {c.messages = c.messages.map(m => { + if (m.content !== undefined) return m; + else return {...m, content: " "}; // the string contains a single space since PaLM2 refuses to answer with empty strings + })}); + } + // Override LLM list with the past llm info (unique LLMs in prior responses) _llmItemsCurrState = past_chat_llms;