Spaces:
Paused
Paused
fix title summarization
Browse files
src/routes/conversation/[id]/+server.ts
CHANGED
|
@@ -122,6 +122,14 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
|
|
| 122 |
];
|
| 123 |
})() satisfies Message[];
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
// we now build the stream
|
| 126 |
const stream = new ReadableStream({
|
| 127 |
async start(controller) {
|
|
@@ -169,7 +177,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
|
|
| 169 |
|
| 170 |
async function saveLast(generated_text: string) {
|
| 171 |
if (!conv) {
|
| 172 |
-
throw
|
| 173 |
}
|
| 174 |
|
| 175 |
const lastMessage = messages[messages.length - 1];
|
|
@@ -200,7 +208,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
|
|
| 200 |
{
|
| 201 |
$set: {
|
| 202 |
messages,
|
| 203 |
-
title:
|
| 204 |
updatedAt: new Date(),
|
| 205 |
},
|
| 206 |
}
|
|
@@ -283,7 +291,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
|
|
| 283 |
{
|
| 284 |
$set: {
|
| 285 |
messages,
|
| 286 |
-
title:
|
| 287 |
updatedAt: new Date(),
|
| 288 |
},
|
| 289 |
}
|
|
|
|
| 122 |
];
|
| 123 |
})() satisfies Message[];
|
| 124 |
|
| 125 |
+
if (conv.title.startsWith("Untitled")) {
|
| 126 |
+
try {
|
| 127 |
+
conv.title = (await summarize(newPrompt)) ?? conv.title;
|
| 128 |
+
} catch (e) {
|
| 129 |
+
console.error(e);
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
// we now build the stream
|
| 134 |
const stream = new ReadableStream({
|
| 135 |
async start(controller) {
|
|
|
|
| 177 |
|
| 178 |
async function saveLast(generated_text: string) {
|
| 179 |
if (!conv) {
|
| 180 |
+
throw error(404, "Conversation not found");
|
| 181 |
}
|
| 182 |
|
| 183 |
const lastMessage = messages[messages.length - 1];
|
|
|
|
| 208 |
{
|
| 209 |
$set: {
|
| 210 |
messages,
|
| 211 |
+
title: conv.title,
|
| 212 |
updatedAt: new Date(),
|
| 213 |
},
|
| 214 |
}
|
|
|
|
| 291 |
{
|
| 292 |
$set: {
|
| 293 |
messages,
|
| 294 |
+
title: conv.title,
|
| 295 |
updatedAt: new Date(),
|
| 296 |
},
|
| 297 |
}
|