This commit is contained in:
Timothy Jaeryang Baek 2024-12-20 15:19:54 -08:00
parent 47318daef0
commit 6524cae407
4 changed files with 14 additions and 14 deletions

View File

@ -985,19 +985,18 @@
} }
}; };
const addMessages = async ({ modelId, messages }) => { const addMessages = async ({ modelId, parentId, messages }) => {
const model = $models.filter((m) => m.id === modelId).at(0); 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 parentMessage = history.messages[parentId];
let parentId = parentMessage ? parentMessage.id : null; let currentParentId = parentMessage ? parentMessage.id : null;
for (const message of messages) { for (const message of messages) {
let messageId = uuidv4(); let messageId = uuidv4();
if (message.role === 'user') { if (message.role === 'user') {
const userMessage = { const userMessage = {
id: messageId, id: messageId,
parentId: parentId, parentId: currentParentId,
childrenIds: [], childrenIds: [],
timestamp: Math.floor(Date.now() / 1000), timestamp: Math.floor(Date.now() / 1000),
...message ...message
@ -1010,11 +1009,11 @@
history.messages[messageId] = userMessage; history.messages[messageId] = userMessage;
parentMessage = userMessage; parentMessage = userMessage;
parentId = messageId; currentParentId = messageId;
} else { } else {
const responseMessage = { const responseMessage = {
id: messageId, id: messageId,
parentId: parentId, parentId: currentParentId,
childrenIds: [], childrenIds: [],
done: true, done: true,
model: model.id, model: model.id,
@ -1031,11 +1030,11 @@
history.messages[messageId] = responseMessage; history.messages[messageId] = responseMessage;
parentMessage = responseMessage; parentMessage = responseMessage;
parentId = messageId; currentParentId = messageId;
} }
} }
history.currentId = parentId; history.currentId = currentParentId;
await tick(); await tick();
if (autoScroll) { if (autoScroll) {

View File

@ -197,6 +197,7 @@
onAdd({ onAdd({
modelId: model, modelId: model,
parentId: id,
messages: messages messages: messages
}); });
}; };

View File

@ -165,9 +165,9 @@
{id} {id}
model={model?.id} model={model?.id}
messages={createMessagesList(history, id)} messages={createMessagesList(history, id)}
onAdd={({ modelId, messages }) => { onAdd={({ modelId, parentId, messages }) => {
console.log(modelId, messages); console.log(modelId, parentId, messages);
onAddMessages({ modelId, messages }); onAddMessages({ modelId, parentId, messages });
closeFloatingButtons(); closeFloatingButtons();
}} }}
/> />

View File

@ -636,8 +636,8 @@
sourceButton.click(); sourceButton.click();
} }
}} }}
onAddMessages={({ modelId, messages }) => { onAddMessages={({ modelId, parentId, messages }) => {
addMessages({ modelId, messages }); addMessages({ modelId, parentId, messages });
}} }}
on:update={(e) => { on:update={(e) => {
const { raw, oldContent, newContent } = e.detail; const { raw, oldContent, newContent } = e.detail;