instructor icon indicating copy to clipboard operation
instructor copied to clipboard

Add unified provider interface with string-based initialization

Open jxnl opened this issue 8 months ago • 1 comments

Summary

  • Adds a unified string-based provider interface with from_provider function for simplified initialization of LLM clients
  • Automatically selects appropriate default modes for each provider
  • Comprehensive error handling with helpful error messages
  • Full test coverage and documentation including a blog post

TODOs before merging

  • [ ] Add additional test cases for the remaining providers beyond OpenAI
  • [ ] Consider adding the Provider enum to the auto_client imports for consistency
  • [ ] Add integration examples showing the new string-based initialization
  • [ ] Update all provider documentation to mention the new initialization method
  • [ ] Add API documentation for from_provider in the API reference

Test plan

  • Verify string parsing works correctly for all provider formats
  • Ensure default modes are correctly applied
  • Test error handling for missing dependencies and invalid provider strings
  • Check that async/sync client creation works correctly
  • Verify proper parameter passing to provider client functions

🤖 Generated with Claude Code


[!IMPORTANT] Introduces a unified provider interface with string-based initialization for LLM clients, including error handling and documentation updates.

  • Behavior:
    • Adds from_provider function in auto_client.py for string-based initialization of LLM clients.
    • Supports synchronous and asynchronous clients with async_client parameter.
    • Automatically selects default modes for each provider.
    • Handles errors for missing dependencies and invalid provider strings.
  • Documentation:
    • Updates README.md with provider initialization examples.
    • Adds blog post string-based-init.md detailing the new interface.
    • Updates index.md in docs/integrations to include new initialization method.
  • Tests:
    • Adds test_auto_client.py to test provider parsing and error handling.
    • Updates test_simple_type_fix.py and test_fizzbuzz_fix.py for Python version compatibility.
  • Misc:
    • Adds run.py example in examples/automodel demonstrating the new interface.
    • Updates pyproject.toml version to 1.8.0.

This description was created by Ellipsis for d7d0d7a4d382b1936f4cc2566271f891e037e099. You can customize this summary. It will automatically update as commits are pushed.

jxnl avatar Apr 18 '25 15:04 jxnl

Deploying instructor-py with  Cloudflare Pages  Cloudflare Pages

Latest commit: d7d0d7a
Status: ✅  Deploy successful!
Preview URL: https://c0300b30.instructor-py.pages.dev
Branch Preview URL: https://automodel.instructor-py.pages.dev

View logs

Tests are passing here in CI

tests/test_auto_client.py ..........................                                             [100%]

ivanleomk avatar May 06 '25 04:05 ivanleomk

Only do literals if it's also unions with the default string.

We don't want to make people upgrade instructor just to use a new model.

jxnl avatar May 06 '25 11:05 jxnl

Let's publish first and then fix docs afterwards.

This is blocking some stuff I want to do in instructor-classify

jxnl avatar May 06 '25 11:05 jxnl