chore: should handle the char extraction better now

This commit is contained in:
Severian
2025-02-13 16:18:52 +08:00
parent 97da46b042
commit 5e4f89cc88
3 changed files with 14 additions and 14 deletions

View File

@@ -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

View File

@@ -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("<scenario>");
const exampleIdx = content.indexOf("<example_dialogs>");
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 || "";

View File

@@ -187,9 +187,9 @@ export default function Home() {
<div className="container mx-auto px-4 py-8">
<div className="flex justify-between items-center mb-4">
<div>
<h1 className="text-3xl font-bold">Sucker v1.3</h1>
<h1 className="text-3xl font-bold">Sucker v1.4</h1>
<p className="text-sm text-muted-foreground">
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.👌
</p>
</div>
<Button