Spaces:
Sleeping
Sleeping
Andrew
commited on
Commit
·
4123958
1
Parent(s):
a374d74
(fix) Harden title generation against leaked reasoning tags
Browse files
src/lib/server/textGeneration/title.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { logger } from "$lib/server/logger";
|
|
| 4 |
import { MessageUpdateType, type MessageUpdate } from "$lib/types/MessageUpdate";
|
| 5 |
import type { Conversation } from "$lib/types/Conversation";
|
| 6 |
import { getReturnFromGenerator } from "$lib/utils/getReturnFromGenerator";
|
|
|
|
| 7 |
|
| 8 |
export async function* generateTitleForConversation(
|
| 9 |
conv: Conversation
|
|
@@ -19,7 +20,7 @@ export async function* generateTitleForConversation(
|
|
| 19 |
|
| 20 |
yield {
|
| 21 |
type: MessageUpdateType.Title,
|
| 22 |
-
title,
|
| 23 |
};
|
| 24 |
} catch (cause) {
|
| 25 |
logger.error(Error("Failed whilte generating title for conversation", { cause }));
|
|
@@ -29,7 +30,9 @@ export async function* generateTitleForConversation(
|
|
| 29 |
export async function generateTitle(prompt: string, modelId?: string) {
|
| 30 |
if (config.LLM_SUMMARIZATION !== "true") {
|
| 31 |
// When summarization is disabled, use the first five words without adding emojis
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
// Tools removed: no tool-based title path
|
|
@@ -52,13 +55,13 @@ Return ONLY the title text.`,
|
|
| 52 |
)
|
| 53 |
.then((summary) => {
|
| 54 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 55 |
-
const trimmed = summary.trim();
|
| 56 |
// Fallback: if empty, return first five words only (no emoji)
|
| 57 |
-
return trimmed || firstFive;
|
| 58 |
})
|
| 59 |
.catch((e) => {
|
| 60 |
logger.error(e);
|
| 61 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 62 |
-
return firstFive;
|
| 63 |
});
|
| 64 |
}
|
|
|
|
| 4 |
import { MessageUpdateType, type MessageUpdate } from "$lib/types/MessageUpdate";
|
| 5 |
import type { Conversation } from "$lib/types/Conversation";
|
| 6 |
import { getReturnFromGenerator } from "$lib/utils/getReturnFromGenerator";
|
| 7 |
+
import { stripThinkBlocks } from "$lib/utils/stripThinkBlocks";
|
| 8 |
|
| 9 |
export async function* generateTitleForConversation(
|
| 10 |
conv: Conversation
|
|
|
|
| 20 |
|
| 21 |
yield {
|
| 22 |
type: MessageUpdateType.Title,
|
| 23 |
+
title: stripThinkBlocks(title).trim() || "New Chat",
|
| 24 |
};
|
| 25 |
} catch (cause) {
|
| 26 |
logger.error(Error("Failed whilte generating title for conversation", { cause }));
|
|
|
|
| 30 |
export async function generateTitle(prompt: string, modelId?: string) {
|
| 31 |
if (config.LLM_SUMMARIZATION !== "true") {
|
| 32 |
// When summarization is disabled, use the first five words without adding emojis
|
| 33 |
+
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 34 |
+
const stripped = stripThinkBlocks(firstFive).trim();
|
| 35 |
+
return stripped || firstFive;
|
| 36 |
}
|
| 37 |
|
| 38 |
// Tools removed: no tool-based title path
|
|
|
|
| 55 |
)
|
| 56 |
.then((summary) => {
|
| 57 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 58 |
+
const trimmed = stripThinkBlocks(String(summary ?? "")).trim();
|
| 59 |
// Fallback: if empty, return first five words only (no emoji)
|
| 60 |
+
return trimmed || stripThinkBlocks(firstFive).trim() || firstFive;
|
| 61 |
})
|
| 62 |
.catch((e) => {
|
| 63 |
logger.error(e);
|
| 64 |
const firstFive = prompt.split(/\s+/g).slice(0, 5).join(" ");
|
| 65 |
+
return stripThinkBlocks(firstFive).trim() || firstFive;
|
| 66 |
});
|
| 67 |
}
|