Skip to content

feat(providers): create modular provider package structure #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Refactor: Create providers package to modularize LLM client implementations

This PR addresses issue #1532 by implementing a modular provider package structure for the instructor library. The approach is minimally invasive, moving only the OpenAI provider as an example while maintaining full backward compatibility.

Changes

  • Created a new providers/ package with:
    • base.py - Base provider interface
    • openai.py - OpenAI provider implementation
    • __init__.py - Provider registry and exports
  • Updated imports in __init__.py and auto_client.py to use the new structure
  • Added deprecation warning to existing from_openai function in client.py
  • Updated README with migration guide

Implementation Details

This implementation follows the structure proposed in issue #1532:

  • providers/base.py contains the base provider interface
  • providers/openai.py contains the moved OpenAI implementation
  • providers/__init__.py exports the provider functions
  • Full backward compatibility is maintained through import forwarding and deprecation warnings

Testing

The implementation maintains backward compatibility:

  • from instructor import from_openai still works (with deprecation warning)
  • from instructor.providers.openai import from_openai works without warning
  • instructor.from_provider("openai/gpt-4") works correctly

TODO

Future work will involve moving the remaining providers to the new structure:

  • Anthropic
  • Google
  • Mistral
  • Cohere
  • Perplexity
  • Groq
  • Writer
  • Bedrock
  • Cerebras
  • Fireworks
  • VertexAI

Link to Devin run

https://app.devin.ai/sessions/8cb6cdfb710c4442a68796becb4d25ec

This PR was requested by Jason Liu (work@jxnl.co)

Co-Authored-By: Jason Liu <jason@jxnl.co>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files. labels May 27, 2025
devin-ai-integration bot and others added 3 commits May 27, 2025 16:25
@jxnl jxnl closed this May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant