Skip to content

Commit

Permalink
fix(chat): Better detection of response on load
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jul 20, 2024
1 parent b3a0466 commit 6fba5ec
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/pages/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ async function setChatName(first_sentence: string) {
}
// Scroll to the bottom of the chat when new messages are added
async function scrollBottom() {
const scrollBottom = () => {
scrollAreaRef.value?.lastElementChild?.scrollIntoView({
behavior: 'smooth',
block: 'end',
});
}
};
// Generate a new response from the AI
async function generatePersonaMessage() {
Expand Down Expand Up @@ -445,8 +445,6 @@ async function sendMessage(content: string) {
// Wipe the attachments
// attachmentsRef.value = [];
nextTick(scrollBottom);
if (!content.trim()) return;
if (content.trim() === '') return;
Expand Down Expand Up @@ -495,12 +493,12 @@ async function setChat(chatId: string) {
await setChatName(loadedChat.messages[0].content);
}
// Determine if there are messages we need to respond to
// NOTE: this is assuming all chats should be initiated by the user
if (loadedChat.messages.length % 2 === 1) {
// Determine if there is a message we need to respond to
const lastMessage = loadedChat.messages.at(-1);
if (lastMessage?.author === 'user') {
await generatePersonaMessage();
}
nextTick(scrollBottom);
scrollBottom();
}
async function updateChatMessageContent(messageIndex: number, content: string, initialContent: string) {
Expand Down

0 comments on commit 6fba5ec

Please sign in to comment.