Skip to main content

Module backends

Module backends 

Source
Expand description

Auto-detect available solver backends and configure the chain.

Production captchaforge ergonomics: a developer should be able to cargo add captchaforge && captchaforge::auto_solve(page).await and have it Just Work — no manual VLM endpoint configuration, no STT server URLs, no tesseract path hunting. This module does the probing and surfaces the result as Capabilities.

§What gets probed

  • Ollama — HTTP probe localhost:11434/api/tags. If reachable, the response lists locally-pulled models. We pick the first model whose name matches a known vision-model pattern (llama3.2-vision, llava, bakllava, qwen2-vl, qwen3-vl, gemma3-vl, pixtral, minicpm-v).
  • Whisper CLIwhich whisper on PATH. The OpenAI Whisper reference CLI; whisper <audio.mp3> --model tiny returns a transcript on stdout.
  • Tesseractwhich tesseract on PATH. Used for canvas / SVG / static-text CAPTCHAs.
  • OpenAIOPENAI_API_KEY env var. If set, OpenAI Whisper API is available as STT fallback.

§Auto-install

Capabilities::ensure_vlm_model will ollama pull a default vision model if Ollama is present but no vision model is. Disabled by default; opt in with [Config::auto_install_backends].

§Example

let caps = captchaforge::backends::probe().await;
if caps.vlm.is_some() {
    println!("VLM ready: {}", caps.vlm.as_ref().unwrap().model);
}

Structs§

Capabilities
Detected backend capabilities. Populated by probe; consumed by crate::config::Config::build_chain to wire solvers conditionally.
OcrBackend
SttBackend
VlmBackend

Enums§

SttKind

Constants§

DEFAULT_VLM_AUTO_PULL
Default vision model to auto-pull when Ollama is present but no vision model is. Picked for size/quality tradeoff: ~7GB, runs on most consumer GPUs and decent CPUs.
DEFAULT_WHISPER_MODEL
Default Whisper model size to use when invoking the local CLI.
VISION_MODEL_PATTERNS
Set of vendor model-name fragments that identify a vision-capable Ollama model. Order matters: earlier entries are preferred when multiple match.

Functions§

pick_best_vision_model
Pure helper: pick the best vision model from a list of Ollama model names by matching against VISION_MODEL_PATTERNS in priority order.
probe
Probe the local environment for available backends. Cheap (~50ms total) — three parallel HTTP/PATH checks.
which
Locate a binary on PATH. Returns the absolute path on hit, None on miss. Pure helper used by both probe_stt and probe_ocr.