instructor icon indicating copy to clipboard operation
instructor copied to clipboard

refactor(v2): complete provider-owned architecture cleanup

Open jxnl-oai opened this issue 6 months ago • 1 comments

Summary

  • move active v2 request construction, schema, and multimodal conversion behind provider-owned modules while retaining lazy v1 compatibility facades
  • collapse instructor/v2/auto_client.py into manifest-driven lazy dispatch, using a shared higher-order builder only for truly OpenAI-compatible construction
  • make ProviderSpec the executable feature contract for modes, partial/iterable streaming, multimodal inputs, and parallel tools
  • deduplicate v2 test setup around the provider manifest, add public-surface Pyright coverage, and document the v2 architecture and migration guidance
  • rewrite the canonical "What's new in Instructor v2?" post as a technical implementation tour and remove the duplicate blog slug
  • add a live model/mode benchmark grid that derives mode cells from ProviderSpec, ranks completed cells by correctness and latency, and skips unavailable API-key or cloud-auth cells safely

Size

  • the provider-ownership cleanup tranche was net -17 lines before the requested benchmark and full technical blog rewrite were added
  • final PR scope is net +761 lines (3,044 additions, 2,283 deletions), reflecting the new benchmark feature and its regression coverage
  • instructor/v2/auto_client.py is now 181 lines

Import Footprint

Measured in fresh Python processes against the prior PR head (ede85cf1) using /usr/bin/time -l:

Import Before After
import instructor 0.01s, 17.5 MB RSS 0.01s, 17.4 MB RSS
from instructor import Mode 0.03s, 20.7 MB RSS 0.02s, 19.5 MB RSS
import instructor.providers.anthropic.client 0.55s, 79.2 MB RSS 0.02s, 19.6 MB RSS

The compatibility facade import no longer pulls in the Anthropic provider implementation or optional SDK at import time.

Validation

  • uv run --frozen ruff format --check instructor tests
  • uv run --frozen ruff check instructor tests examples/v2-model-mode-benchmark
  • uv run --frozen pytest tests/v2 tests/test_lazy_imports.py tests/providers/test_auto_client.py tests/multimodal/test_multimodal.py tests/processing/test_process_response.py tests/processing/test_function_calls.py tests/test_streaming_reask_bug.py tests/test_genai_reask.py tests/core/test_retry_json_mode.py tests/test_update_total_usage.py -q (1751 passed, 193 skipped)
  • uv run --frozen --all-extras ty check instructor/v2
  • uv run --frozen --all-extras ty check --config-file ty-tests.toml tests
  • uv run --frozen --all-extras ty check instructor/v2 tests/v2/test_model_mode_benchmark.py examples/v2-model-mode-benchmark/run.py
  • uv run --frozen --all-extras --with 'pyright==1.1.408' pyright tests/typing/test_public_surface.py
  • uv run --frozen mkdocs build --strict
  • credential-free smoke run of uv run --frozen python examples/v2-model-mode-benchmark/run.py --trials 1 (all unconfigured cells skipped without live requests)
  • independent reviewer pass completed with no confirmed merge-blocking findings

The pytest warning output is limited to compatibility deprecation coverage, third-party Fireworks Pydantic warnings, and one existing pytest marker warning.

jxnl-oai avatar May 20 '26 14:05 jxnl-oai

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
instructor 497a454c Commit Preview URL

Branch Preview URL
Jun 07 2026, 10:25 PM