From 5e4f89cc881bf18ebfc27c46b26eb74d0b94bbe4 Mon Sep 17 00:00:00 2001 From: Severian Date: Thu, 13 Feb 2025 16:18:52 +0800 Subject: [PATCH] chore: should handle the char extraction better now --- README.md | 1 + src/app/api/proxy/route.ts | 23 +++++++++++------------ src/app/page.tsx | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index add3791..286de57 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Check package.json for commands, I can't be bothered. ### Changelog +- 1.4: Mooth just keeps finding bugs, damn. - 1.3: Mooth found a bug, fixed it. - 1.2: Fix for Janitor having changed their prompt system - 1.1: Fix for R1 handling change, blank user persona bug diff --git a/src/app/api/proxy/route.ts b/src/app/api/proxy/route.ts index 3147000..1a754cd 100644 --- a/src/app/api/proxy/route.ts +++ b/src/app/api/proxy/route.ts @@ -38,28 +38,27 @@ interface PersonaMatch { content: string; } -function findTagsBetween(content: string, startMarker: string, endMarker: string): PersonaMatch[] { +function findTagsBetween(content: string, startMarker: string): PersonaMatch[] { const startMarkerTag = `<${startMarker}>`; - const endMarkerTag = `<${endMarker}>`; const startIdx = content.indexOf(startMarkerTag); if (startIdx === -1) return []; - // Look for any XML-style tags after the system tag - const section = content.slice(startIdx); + const scenarioIdx = content.indexOf(""); + const exampleIdx = content.indexOf(""); + + let endIdx = content.length; + if (scenarioIdx !== -1) endIdx = Math.min(endIdx, scenarioIdx); + if (exampleIdx !== -1) endIdx = Math.min(endIdx, exampleIdx); + + const section = content.slice(startIdx, endIdx); const matches: PersonaMatch[] = []; - // Match any tag that comes before the scenario tag const tagPattern = /<([^/>\s][^>]*)>([\s\S]*?)<\/\1>/g; let match; try { while ((match = tagPattern.exec(section)) !== null) { - // Stop if we hit the scenario tag - if (match[1] === endMarker) { - break; - } - // Skip the system tag if (match[1] !== startMarker) { matches.push({ @@ -95,8 +94,8 @@ function extractCardData(messages: Message[]): CardData { const content0 = messages[0].content; const content1 = messages[2].content; - // Find all persona tags between system and scenario, take the last one as character - const personas = findTagsBetween(content0, "system", "scenario"); + // Find all persona tags between system and the first optional tag (scenario or example_dialogs) + const personas = findTagsBetween(content0, "system"); const charPersona = personas[personas.length - 1]; const charName = charPersona?.tag || ""; diff --git a/src/app/page.tsx b/src/app/page.tsx index 43d397d..6773cbf 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -187,9 +187,9 @@ export default function Home() {
-

Sucker v1.3

+

Sucker v1.4

- I still hate making these changes, but Mooth found a bug so I fixed it. + Mooth's on a bug hunting spree for some reason.👌