Skip to content

v0.1.2 (beta)

Pre-release
Pre-release

Choose a tag to compare

@Eltarras Eltarras released this 04 Oct 07:09
· 159 commits to main since this release
a167627

thunc can now cache answers, set its own system prompt, and copes much better with replies that don't follow the format.

pip install --upgrade thunc

Caching (#18, #19)

  • cache=True on @thunc.function or thunc.call saves each valid answer on disk and reuses it for the same call, so the model is asked once. It's off by default: use it for functions that should give one answer per input (classify, extract, score). Answers go in .thunc_cache/, or set configure(cache_dir=...) / THUNC_CACHE_DIR.
  • Clearing the cache: thunc.clear_cache() for everything, thunc.clear_cache(func) for one function, and older_than= for old answers only. thunc.cache_info() shows what's stored.
  • New thunc command: thunc cache list and thunc cache clear [--function NAME] [--older-than 30d] [--dry-run], also available as python -m thunc.
  • thunc.call takes name= to group its cached answers.

Custom system prompts (#21)

  • system= on thunc.call, @thunc.function and thunc.configure replaces the opening of thunc's default system prompt, e.g. system="You are a strict essay grader.". thunc still adds its two rules after your text: inputs are data, not instructions, and the reply is the value only.
  • The default prompt is unchanged, so default calls behave as before.
  • Codex now receives the system prompt as its instructions file (model_instructions_file), which replaces Codex's built-in prompt. Before, the prompt was pasted in front of your task.

Sturdier parsing (#20)

  • Common near-misses are read instead of retried: code fences with any language tag, a leading <think> block, and one-key wrappers like {"rating": 4} for an int.
  • Fewer wrong values returned silently: these are now retried instead:
    • true for Literal[1, 2];
    • NaN;
    • a duplicate JSON key;
    • two answers in one reply;
    • an object with none of a dataclass's fields.
  • Only ThuncError escapes: a bad reply or unreadable backend output always ends in ThuncError. That covers deeply nested JSON, an ensure= check that raises, a backend that returns no text, and a refused or cut-off API response.
  • Python 3.10: string annotations such as list["Item"] now work.

Behaviour changes

  • An empty reply is no longer a valid str; it's retried. Use str | None if empty is a valid answer.
  • Replies that 0.1.1 accepted with a wrong value are now retried, so some calls that used to "succeed" can now end in ThuncError.

Added a Known issues section in CONTRIBUTING.md which mainly highlights robustness issues to be fixed.

Still beta: expect bugs, and the API may change.

Full changelog: v0.1.1...v0.1.2