feat(captcha): self-consistency voting, optimized prompts, no-targets signal

- Add Samples to TextOptions/GridOptions; N>1 runs N solves at temp 0.5
  and majority-votes (text: most frequent; grid: tiles in strict majority).
  N<=1 keeps the single deterministic call path unchanged.
- Add NoTargets to GridResult so callers know to click Verify instead of
  looping; prompt instructs empty tiles + no_targets:true when nothing matches.
- Grid prompt: numbered cells 0..R*C-1, select any partial overlap.
- Text prompt: disambiguate similar glyphs (0/O 1/l/I 5/S 2/Z 8/B).
- Rotation prompt: reason step-by-step then emit final JSON.
This commit is contained in:
2026-06-07 17:37:18 +01:00
parent c8edd4aa06
commit edb655f590
5 changed files with 270 additions and 11 deletions
+18
View File
@@ -31,3 +31,21 @@ func TestSolveTextRetriesOnGarbage(t *testing.T) {
t.Fatalf("expected 2 attempts (one retry), got %d", len(f.VisionCalls))
}
}
func TestSolveTextVoting(t *testing.T) {
f := &llm.Fake{VisionResponses: []string{
`{"text":"ab12","confidence":0.7}`,
`{"text":"ab12","confidence":0.7}`,
`{"text":"ab13","confidence":0.9}`,
}}
res, err := SolveText(context.Background(), f, []byte{1}, "image/png", TextOptions{Samples: 3})
if err != nil {
t.Fatal(err)
}
if res.Text != "ab12" {
t.Fatalf("voted text %q, want ab12", res.Text)
}
if len(f.VisionCalls) != 3 {
t.Fatalf("expected 3 vision calls, got %d", len(f.VisionCalls))
}
}