From 1217513ae37e078f8fcd0e4f0cecb8d8599f8094 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Fri, 10 Nov 2023 20:10:29 +0800 Subject: [PATCH] fix undefined on tool_calls --- src/chatbox.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chatbox.tsx b/src/chatbox.tsx index 5aa2381..8fb68f7 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -4,6 +4,7 @@ import { createRef } from "preact"; import { StateUpdater, useEffect, useState } from "preact/hooks"; import { ChatStore, + ChatStoreMessage, STORAGE_NAME_TEMPLATE, STORAGE_NAME_TEMPLATE_API, TemplateAPI, @@ -137,14 +138,16 @@ export default function ChatBOX(props: { chatStore.cost += cost; addTotalCost(cost); - chatStore.history.push({ + const newMsg: ChatStoreMessage = { role: "assistant", content, - tool_calls: allChunkTool, hide: false, token: responseTokenCount, example: false, - }); + }; + if (allChunkTool.length > 0) newMsg.tool_calls = allChunkTool; + + chatStore.history.push(newMsg); // manually copy status from client to chatStore chatStore.maxTokens = client.max_tokens; chatStore.tokenMargin = client.tokens_margin;