P5a: digests cite pages; sift_pdf_* metrics; sift fetch --pages/--grep; skill, unit and README
Digest systemPrompt gains a page-cite instruction and PromptVersion is 3.
Add the sift_pdf_* metric series (extract_total{outcome}, extract_seconds,
pages_total, pool_wait_seconds, cache_hits_total) to internal/metrics and wire
ObservePDF/ObservePDFWait/PDFCacheHit into internal/api/pdf.go. Refactor
cmd/sift/fetchcmd.go to a fetchOpts struct with parseFetchOpts and fetchBody,
adding --pages/--grep. Update skill/SKILL.md, set nix MemoryMax to 1G, and add a
PDF documents section to the README.
Co-Authored-By: ornith-1.5-35b-a3b <ornith-1.5-35b-a3b@llama.cpp.invalid>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package digest
|
||||
|
||||
// P5a task 07: a digest of a PDF cites pages. The page markers come from internal/pdfdoc; the
|
||||
// prompt tells the model to use them, and the prompt version moves so cached digests made with
|
||||
// the old prompt are not served.
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPromptCitesPages(t *testing.T) {
|
||||
if !strings.Contains(systemPrompt, "--- page N ---") || !strings.Contains(systemPrompt, "(p. N)") {
|
||||
t.Errorf("system prompt must tell the model to cite pages from --- page N --- markers:\n%s", systemPrompt)
|
||||
}
|
||||
if PromptVersion == "2" {
|
||||
t.Error("PromptVersion must change with the prompt (was \"2\")")
|
||||
}
|
||||
}
|
||||
|
||||
// Page markers survive chunking whole: none is cut across two chunks. (This holds for today's
|
||||
// Split, whose paragraph boundaries fall around each marker; the test keeps it that way.)
|
||||
func TestSplitKeepsPageMarkers(t *testing.T) {
|
||||
var b strings.Builder
|
||||
for p := 1; p <= 40; p++ {
|
||||
b.WriteString("--- page " + strconv.Itoa(p) + " ---\n\n")
|
||||
b.WriteString(strings.Repeat("word ", 600))
|
||||
b.WriteString("\n\n")
|
||||
}
|
||||
marker := regexp.MustCompile(`--- page \d+ ---`)
|
||||
n := 0
|
||||
for _, c := range Split(b.String(), ChunkTokens) {
|
||||
n += len(marker.FindAllString(c, -1))
|
||||
}
|
||||
if n != 40 {
|
||||
t.Errorf("%d whole page markers across the chunks, want 40", n)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user