fix: stop transcript leakage and repetition loops in Generic chat template
Backend (inference-server/compat.rs): - PreparedPrompt now carries extra_stop_sequences injected by template - Generic template injects User:/System:/Assistant:/Human: stop sequences to prevent the model from continuing the transcript after its reply - Increased repeat_penalty 1.15→1.3 and repeat_last_n 256→512 to break repetition loops more aggressively Backend (inference-server/routes.rs): - Merge template extra_stop_sequences into sampler before inference Frontend (chat.ts): - Added 'System:' and 'Human:' to CHAT_TRANSCRIPT_STOP_SEQUENCES - Extended TRANSCRIPT_LEAKAGE_PATTERN to include 'Human:' Frontend (ChatView.tsx): - buildApiMessages now strips leaked transcript from assistant messages before sending history back to the model - Reduced history window to 20 messages to limit context pollution
This commit is contained in:
1 parent
5f86c69b03
commit
88f4319c3f
6 files changed
+1951
-7
No files matched your search
@@ -205,9 +205,16 @@ export default function ChatView({
|
||||
const buildApiMessages = useCallback((cid: number) => {
|
||||
const history = db.query<{ role: string; content: string }>(
|
||||
"SELECT role, content FROM messages WHERE chat_id = ? AND content != '' AND content NOT LIKE '⚠️ Error:%' AND content != 'internal error' ORDER BY created_at DESC LIMIT ?",
|
||||
[cid, 100],
|
||||
[cid, 20],
|
||||
).reverse();
|
||||
return history;
|
||||
// Strip any leaked reasoning/transcript from assistant messages before sending back to model
|
||||
return history.map((msg) => {
|
||||
if (msg.role !== "assistant") return msg;
|
||||
// Remove content after transcript leakage markers
|
||||
const leakageIdx = msg.content.search(/(?:^|\n)\s*(?:System|User|Assistant|Human):/i);
|
||||
const cleaned = leakageIdx > 0 ? msg.content.slice(0, leakageIdx).trimEnd() : msg.content;
|
||||
return { ...msg, content: cleaned };
|
||||
}).filter((msg) => msg.content.trim() !== "");
|
||||
}, [db]);
|
||||
|
||||
const send = useCallback(async (text: string, fromChatId?: number, replaceAssistantId?: number) => {
|
||||
|
||||
@@ -7,7 +7,7 @@ export interface ParsedAssistantResponse {
|
||||
|
||||
const THINK_OPEN = "<think>";
|
||||
const THINK_CLOSE = "</think>";
|
||||
const TRANSCRIPT_LEAKAGE_PATTERN = /(?:^|\n)\s*(?:System|User|Assistant):/i;
|
||||
const TRANSCRIPT_LEAKAGE_PATTERN = /(?:^|\n)\s*(?:System|User|Assistant|Human):/i;
|
||||
|
||||
export const CHAT_TRANSCRIPT_STOP_SEQUENCES = [
|
||||
"\nSystem:",
|
||||
@@ -16,6 +16,9 @@ export const CHAT_TRANSCRIPT_STOP_SEQUENCES = [
|
||||
"\n\nSystem:",
|
||||
"\n\nUser:",
|
||||
"\n\nAssistant:",
|
||||
"System:",
|
||||
"\nHuman:",
|
||||
"\n\nHuman:",
|
||||
];
|
||||
|
||||
export function buildChatTitle(text: string): string {
|
||||
|
||||
Reference in new issue
Block a user