fix: if streaming did not work, get message from end

This commit is contained in:
Gabriel Almeida 2023-05-06 08:28:54 -03:00
commit 234358bc6e

View file

@ -56,15 +56,27 @@ export default function ChatModal({
//add proper type signature for function
function updateLastMessage({str,thought}:{str?: string, thought?: string}) {
function updateLastMessage({
str,
thought,
end = false,
}: {
str?: string;
thought?: string;
// end param default is false
end?: boolean;
}) {
setChatHistory((old) => {
let newChat = [...old];
if (str) {
if (end && !newChat[newChat.length - 1].message) {
newChat[newChat.length - 1].message = str;
}
newChat[newChat.length - 1].message =
newChat[newChat.length - 1].message + str;
}
if (thought) {
newChat[newChat.length - 1].thought = thought
newChat[newChat.length - 1].thought = thought;
}
return newChat;
});
@ -120,7 +132,11 @@ export default function ChatModal({
}
if (data.type === "end") {
if (data.intermediate_steps) {
updateLastMessage({thought:data.intermediate_steps});
updateLastMessage({
str: data.message,
thought: data.intermediate_steps,
end: true,
});
}
setLockChat(false);
isStream = false;