From b86760ce681926f063738bafa0d4fe05f814a1bf Mon Sep 17 00:00:00 2001 From: Udara Jay Date: Sat, 11 May 2024 21:25:54 -0400 Subject: [PATCH] Fix: close chat while AI is responding --- src/renderer/pages/Pile/Chat/index.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer/pages/Pile/Chat/index.jsx b/src/renderer/pages/Pile/Chat/index.jsx index fc947a1..85beacc 100644 --- a/src/renderer/pages/Pile/Chat/index.jsx +++ b/src/renderer/pages/Pile/Chat/index.jsx @@ -48,11 +48,12 @@ export default function Chat() { const appendToLastSystemMessage = (token) => { setHistory((history) => { + if (!history || history.length === 0) return []; const last = history[history.length - 1]; - if (last.role === 'system') { + if (last?.role === 'system') { return [ ...history.slice(0, -1), - { role: 'system', content: last.content + (token ?? '') }, + { role: 'system', content: last?.content + (token ?? '') }, ]; } });