Skip to content

Commit 8b0abbc

Browse files
authored
add createdAt and udpatedAt to new messages (#1062)
1 parent 69b2997 commit 8b0abbc

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/routes/conversation/[id]/+server.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,31 @@ export async function POST({ request, locals, params, getClientAddress }) {
214214
if (messageToRetry.from === "user" && newPrompt) {
215215
// add a sibling to this message from the user, with the alternative prompt
216216
// add a children to that sibling, where we can write to
217-
const newUserMessageId = addSibling(conv, { from: "user", content: newPrompt }, messageId);
217+
const newUserMessageId = addSibling(
218+
conv,
219+
{ from: "user", content: newPrompt, createdAt: new Date(), updatedAt: new Date() },
220+
messageId
221+
);
218222
messageToWriteToId = addChildren(
219223
conv,
220-
{ from: "assistant", content: "", files: hashes },
224+
{
225+
from: "assistant",
226+
content: "",
227+
files: hashes,
228+
createdAt: new Date(),
229+
updatedAt: new Date(),
230+
},
221231
newUserMessageId
222232
);
223233
messagesForPrompt = buildSubtree(conv, newUserMessageId);
224234
} else if (messageToRetry.from === "assistant") {
225235
// we're retrying an assistant message, to generate a new answer
226236
// just add a sibling to the assistant answer where we can write to
227-
messageToWriteToId = addSibling(conv, { from: "assistant", content: "" }, messageId);
237+
messageToWriteToId = addSibling(
238+
conv,
239+
{ from: "assistant", content: "", createdAt: new Date(), updatedAt: new Date() },
240+
messageId
241+
);
228242
messagesForPrompt = buildSubtree(conv, messageId);
229243
messagesForPrompt.pop(); // don't need the latest assistant message in the prompt since we're retrying it
230244
}
@@ -410,6 +424,8 @@ export async function POST({ request, locals, params, getClientAddress }) {
410424

411425
let buffer = "";
412426

427+
messageToWriteTo.updatedAt = new Date();
428+
413429
try {
414430
const endpoint = await model.getEndpoint();
415431
for await (const output of await endpoint({
@@ -460,7 +476,6 @@ export async function POST({ request, locals, params, getClientAddress }) {
460476
}, output.generated_text.trimEnd());
461477

462478
messageToWriteTo.content = previousText + text;
463-
messageToWriteTo.updatedAt = new Date();
464479
}
465480
}
466481
} catch (e) {

0 commit comments

Comments
 (0)