Files
lukaszraczylo edb655f590 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.
2026-06-07 17:37:18 +01:00

37 lines
1.3 KiB
Go

package captcha
import (
"context"
"encoding/json"
"fmt"
"github.com/lukaszraczylo/captcha-solver-mcp/internal/llm"
)
// RotationResult is a best-effort FunCaptcha/rotation answer.
type RotationResult struct {
Choice int `json:"choice"`
Rotations int `json:"rotations"`
Confidence float64 `json:"confidence"`
}
// SolveRotation handles FunCaptcha-style rotation/choice puzzles (best-effort).
func SolveRotation(ctx context.Context, c llm.Client, img []byte, mediaType, instruction string) (RotationResult, error) {
prompt := fmt.Sprintf(
"You are solving a rotation/choice puzzle captcha. Instruction: %q. "+
"If asked to pick one image, return its 0-based index as choice. "+
"If asked to rotate, return the number of clockwise steps as rotations. "+
"First reason step-by-step about the correct orientation/choice, then give the final answer "+
`as the last thing you output: compact JSON {"choice":<int>,"rotations":<int>,"confidence":<0..1>}.`,
instruction)
raw, err := c.Vision(ctx, prompt, []llm.Image{{MediaType: mediaType, Data: img}}, llm.Options{})
if err != nil {
return RotationResult{}, err
}
var res RotationResult
if err := json.Unmarshal([]byte(extractJSON(raw)), &res); err != nil {
return RotationResult{}, fmt.Errorf("model did not return parseable rotation answer")
}
return res, nil
}