Skip to content

Commit

Permalink
Do not fetch history if the function is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Mar 7, 2024
1 parent 4adc59d commit 99559bd
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@ function ChatBody({
* Effect: fetch history and config on initial render
*/
useEffect(() => {
async function getConfig() {
ChatService.getConfig()
.then(config =>
setSendWithShiftEnter(config.send_with_shift_enter ?? false)
)
.catch(e => console.error(e));
}

async function fetchHistory() {
try {
const [history, config] = await Promise.all([
chatModel.getHistory?.() ??
new Promise<ChatService.ChatHistory>(r => r({ messages: [] })),
ChatService.getConfig()
]);
setSendWithShiftEnter(config.send_with_shift_enter ?? false);
setMessages(history.messages);
} catch (e) {
console.error(e);
if (!chatModel.getHistory) {
return;
}
chatModel
.getHistory()
.then(history => setMessages(history.messages))
.catch(e => console.error(e));
}

getConfig();
fetchHistory();
}, [chatModel]);

Expand All @@ -59,7 +64,6 @@ function ChatBody({
setMessages([]);
return;
}

setMessages(messageGroups => [...messageGroups, message]);
}

Expand Down

0 comments on commit 99559bd

Please sign in to comment.