prodigy.analysis.ai_candidates¶
Loop invariants proposed by a language model and checked by Prodigy.
The model only proposes candidates. Every candidate goes through the same exact check as an
invariant typed in by hand (strategies evt_invariant and evt_subinvariant), so a wrong
answer makes an attempt fail but never makes a result unsound. When a candidate is rejected, the
next request tells the model why (e.g. Φ(I) − I), so it can correct itself.
Answers are untrusted input. Before any computer algebra system sees a candidate (SymPy’s parser
evaluates Python code), it must consist of numbers, the program’s variables and parameters,
+ - * / ^, parentheses, sqrt and exp, and parse as a pGCL expression.
Configuration, read from the environment of prodigy (it never reaches the browser):
ANTHROPIC_API_KEY: Claude API, modelPRODIGY_AI_MODEL(defaultclaude-sonnet-5-5);ANTHROPIC_WORKSPACE_IDfor a key that is not scoped to a workspace.OPENAI_API_KEYand/orPRODIGY_AI_BASE_URLwithPRODIGY_AI_MODEL: an OpenAI-compatible chat-completions API, e.g.http://localhost:11434/v1for a local model served by Ollama.PRODIGY_AI_PROVIDER(anthropicoropenai) chooses if both are configured;PRODIGY_AI_TIMEOUT: seconds per request (default 120).
- exception AIConfigurationError[source]¶
Bases:
ExceptionNo language model is configured, or its configuration is incomplete.
- exception CandidateError[source]¶
Bases:
ValueErrorAn answer contains no admissible candidate.
- prompt(form, program, loop, variables, parameters, entering, rejected)[source]¶
The request for a candidate of kind
form(seeFORMS) forloop.
- candidate_from_answer(answer, names)[source]¶
The candidate in a model’s answer: its last
ANSWER:line, else the last line of its last code block or of the answer.Raises
CandidateErrorunless it is an expression overnames, numbers,+ - * / ^, parentheses,sqrtandexpthat parses as a pGCL expression.