Skip to content

Refactor: Create providers package to modularize LLM client implementations #1532

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

Open
jxnl opened this issue May 16, 2025 · 0 comments
Open
Labels
enhancement New feature or request python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files.

Comments

@jxnl
Copy link
Collaborator

jxnl commented May 16, 2025

The current flat structure with individual client_*.py files has become difficult to maintain as we add more providers. We should reorganize into a proper provider package structure.

Current problems:

  • Flat directory with many provider-specific files cluttering the root namespace
  • Related provider code is scattered across client_*.py and process_response.py
  • No clear interface that providers must implement
  • Difficult to discover which functionality is supported by which provider

Proposed solution:

instructor/
├── providers/
│   ├── __init__.py     # Provider registry and common utilities
│   ├── base.py         # Provider interface/protocol
│   ├── oai_provider.py # OpenAI implementation (avoid name conflict)
│   ├── claude.py       # Anthropic implementation 
│   └── ...             # Other providers

Each provider module would contain:

  1. Factory functions (e.g., from_openai)
  2. Provider-specific response handlers (moved from process_response.py)
  3. Provider-specific validation logic (mode support, etc.)
  4. Provider-specific utility functions
  5. Structured comments documenting supported features

Implementation steps:

  1. Create providers/ directory with placeholder __init__.py and base.py
  2. Move each client_*.py file into corresponding provider module with non-conflicting names
  3. Move provider-specific handlers from process_response.py to provider modules
  4. Update imports throughout codebase
  5. Update type annotations to reflect new structure
@jxnl jxnl added the enhancement New feature or request label May 16, 2025
@github-actions github-actions bot added python Pull requests that update python code size:M This PR changes 30-99 lines, ignoring generated files. labels May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

1 participant