e1c8923b012df6ecf091a30de611f494d7f82416

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Clean up LLM responses

Diff

This diff is truncated to protect this page.

 1diff --git a/internal/llm/contract.go b/internal/llm/contract.go
 2index b50b2dd89930fc18b35003229319348346d24322..ad761ffc6af58876b99ce88570b124066af5314d 100644
 3--- a/internal/llm/contract.go
 4+++ b/internal/llm/contract.go
 5@@ -54,8 +54,10 @@ var (
 6 )
 7 
 8 // parseFields splits a raw model reply into FIELD|value lines. Surrounding
 9-// whitespace is tolerated and blank lines are skipped. A line without a pipe,
10-// an unknown field name, or a repeated field is a recoverable error.
11+// whitespace is tolerated and blank lines are skipped. A trailing pipe on a
12+// value is dropped: the model sometimes glues the empty next field's pipe onto
13+// the previous line. A line without a pipe, an unknown field name, or a
14+// repeated field is a recoverable error.
15 func parseFields(raw string, names []string) (map[string]string, error) {
16 	valid := make(map[string]bool, len(names))
17 	for _, n := range names {
18@@ -72,7 +74,7 @@ func parseFields(raw string, names []string) (map[string]string, error) {
19 			return nil, &ContractError{Kind: InvalidFormat, Field: trimmed}
20 		}
21 		name = strings.TrimSpace(name)
22-		value = strings.TrimSpace(value)
23+		value = strings.TrimSuffix(strings.TrimSpace(value), "|")
24 		if !valid[name] {
25 			return nil, &ContractError{Kind: InvalidFormat, Field: name}
26 		}
27diff --git a/internal/llm/prompt.go b/internal/llm/prompt.go
28index 19efad03c2f812d022c7b9ceaedcc706645b9831..997498ffe1a5e7e64fbd0bd6ddc2c313a3c70187 100644
29--- a/internal/llm/prompt.go
30+++ b/internal/llm/prompt.go
31@@ -63,7 +63,7 @@ New characters
32 - A one-off ambient line from a person who is not the TALK partner (background grunts, distant chatter) needs no character sheet and may appear as usual.
33 
34 Reply format (mandatory)
35-Every reply you send must be exactly these six lines, in this order, with nothing before, after, or between them. No markdown, no code fences, no extra text. Each line is its key, a pipe |, then the value.