Spaces:
Running
Running
add createdAt and udpatedAt to new messages (#1062)
Browse files
src/routes/conversation/[id]/+server.ts
CHANGED
@@ -214,17 +214,31 @@ export async function POST({ request, locals, params, getClientAddress }) {
|
|
214 |
if (messageToRetry.from === "user" && newPrompt) {
|
215 |
// add a sibling to this message from the user, with the alternative prompt
|
216 |
// add a children to that sibling, where we can write to
|
217 |
-
const newUserMessageId = addSibling(
|
|
|
|
|
|
|
|
|
218 |
messageToWriteToId = addChildren(
|
219 |
conv,
|
220 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
newUserMessageId
|
222 |
);
|
223 |
messagesForPrompt = buildSubtree(conv, newUserMessageId);
|
224 |
} else if (messageToRetry.from === "assistant") {
|
225 |
// we're retrying an assistant message, to generate a new answer
|
226 |
// just add a sibling to the assistant answer where we can write to
|
227 |
-
messageToWriteToId = addSibling(
|
|
|
|
|
|
|
|
|
228 |
messagesForPrompt = buildSubtree(conv, messageId);
|
229 |
messagesForPrompt.pop(); // don't need the latest assistant message in the prompt since we're retrying it
|
230 |
}
|
@@ -410,6 +424,8 @@ export async function POST({ request, locals, params, getClientAddress }) {
|
|
410 |
|
411 |
let buffer = "";
|
412 |
|
|
|
|
|
413 |
try {
|
414 |
const endpoint = await model.getEndpoint();
|
415 |
for await (const output of await endpoint({
|
@@ -460,7 +476,6 @@ export async function POST({ request, locals, params, getClientAddress }) {
|
|
460 |
}, output.generated_text.trimEnd());
|
461 |
|
462 |
messageToWriteTo.content = previousText + text;
|
463 |
-
messageToWriteTo.updatedAt = new Date();
|
464 |
}
|
465 |
}
|
466 |
} catch (e) {
|
|
|
214 |
if (messageToRetry.from === "user" && newPrompt) {
|
215 |
// add a sibling to this message from the user, with the alternative prompt
|
216 |
// add a children to that sibling, where we can write to
|
217 |
+
const newUserMessageId = addSibling(
|
218 |
+
conv,
|
219 |
+
{ from: "user", content: newPrompt, createdAt: new Date(), updatedAt: new Date() },
|
220 |
+
messageId
|
221 |
+
);
|
222 |
messageToWriteToId = addChildren(
|
223 |
conv,
|
224 |
+
{
|
225 |
+
from: "assistant",
|
226 |
+
content: "",
|
227 |
+
files: hashes,
|
228 |
+
createdAt: new Date(),
|
229 |
+
updatedAt: new Date(),
|
230 |
+
},
|
231 |
newUserMessageId
|
232 |
);
|
233 |
messagesForPrompt = buildSubtree(conv, newUserMessageId);
|
234 |
} else if (messageToRetry.from === "assistant") {
|
235 |
// we're retrying an assistant message, to generate a new answer
|
236 |
// just add a sibling to the assistant answer where we can write to
|
237 |
+
messageToWriteToId = addSibling(
|
238 |
+
conv,
|
239 |
+
{ from: "assistant", content: "", createdAt: new Date(), updatedAt: new Date() },
|
240 |
+
messageId
|
241 |
+
);
|
242 |
messagesForPrompt = buildSubtree(conv, messageId);
|
243 |
messagesForPrompt.pop(); // don't need the latest assistant message in the prompt since we're retrying it
|
244 |
}
|
|
|
424 |
|
425 |
let buffer = "";
|
426 |
|
427 |
+
messageToWriteTo.updatedAt = new Date();
|
428 |
+
|
429 |
try {
|
430 |
const endpoint = await model.getEndpoint();
|
431 |
for await (const output of await endpoint({
|
|
|
476 |
}, output.generated_text.trimEnd());
|
477 |
|
478 |
messageToWriteTo.content = previousText + text;
|
|
|
479 |
}
|
480 |
}
|
481 |
} catch (e) {
|