diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte
index 1b8e1e3ea..4b4fab6e1 100644
--- a/src/lib/components/chat/Chat.svelte
+++ b/src/lib/components/chat/Chat.svelte
@@ -985,6 +985,70 @@
}
};
+ const addMessages = async ({ modelId, messages }) => {
+ const model = $models.filter((m) => m.id === modelId).at(0);
+ const messageList = createMessagesList(history.currentId);
+
+ let parentMessage = messageList.length !== 0 ? messageList.at(-1) : null;
+ let parentId = parentMessage ? parentMessage.id : null;
+ for (const message of messages) {
+ let messageId = uuidv4();
+
+ if (message.role === 'user') {
+ const userMessage = {
+ id: messageId,
+ parentId: parentId,
+ childrenIds: [],
+ timestamp: Math.floor(Date.now() / 1000),
+ ...message
+ };
+
+ if (parentMessage) {
+ parentMessage.childrenIds.push(messageId);
+ history.messages[parentMessage.id] = parentMessage;
+ }
+
+ history.messages[messageId] = userMessage;
+ parentMessage = userMessage;
+ parentId = messageId;
+ } else {
+ const responseMessage = {
+ id: messageId,
+ parentId: parentId,
+ childrenIds: [],
+ done: true,
+ model: model.id,
+ modelName: model.name ?? model.id,
+ modelIdx: 0,
+ timestamp: Math.floor(Date.now() / 1000),
+ ...message
+ };
+
+ if (parentMessage) {
+ parentMessage.childrenIds.push(messageId);
+ history.messages[parentMessage.id] = parentMessage;
+ }
+
+ history.messages[messageId] = responseMessage;
+ parentMessage = responseMessage;
+ parentId = messageId;
+ }
+ }
+
+ history.currentId = parentId;
+ await tick();
+
+ if (autoScroll) {
+ scrollToBottom();
+ }
+
+ if (messages.length === 0) {
+ await initChatHandler();
+ } else {
+ await saveChatHandler($chatId);
+ }
+ };
+
const chatCompletionEventHandler = async (data, message, chatId) => {
const { id, done, choices, sources, selectedModelId, error, usage } = data;
@@ -1937,6 +2001,7 @@
{regenerateResponse}
{mergeResponses}
{chatActionHandler}
+ {addMessages}
bottomPadding={files.length > 0}
/>
diff --git a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte
index 97b01e05d..a6ac48ce9 100644
--- a/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte
+++ b/src/lib/components/chat/ContentRenderer/FloatingButtons.svelte
@@ -26,6 +26,7 @@
let prompt = '';
let responseContent = null;
+ let responseDone = false;
const askHandler = async () => {
if (!model) {
@@ -69,6 +70,7 @@
for (const line of lines) {
if (line.startsWith('data: ')) {
if (line.startsWith('data: [DONE]')) {
+ responseDone = true;
continue;
} else {
// Parse the JSON chunk
@@ -145,6 +147,7 @@
for (const line of lines) {
if (line.startsWith('data: ')) {
if (line.startsWith('data: [DONE]')) {
+ responseDone = true;
continue;
} else {
// Parse the JSON chunk
@@ -181,7 +184,7 @@
};
const addHandler = async () => {
- newMessages = [
+ const messages = [
{
role: 'user',
content: prompt
@@ -192,13 +195,15 @@
}
];
- responseContent = null;
-
- onAdd();
+ onAdd({
+ modelId: model,
+ messages: messages
+ });
};
export const closeHandler = () => {
responseContent = null;
+ responseDone = false;
floatingInput = false;
floatingInputValue = '';
};
@@ -306,6 +311,17 @@
{:else}