feat(providers): create modular provider package structure #1568
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
providers/
package with:base.py
- Base provider interfaceopenai.py
- OpenAI provider implementation__init__.py
- Provider registry and exports__init__.py
andauto_client.py
to use the new structurefrom_openai
function inclient.py
Implementation Details
This implementation follows the structure proposed in issue #1532:
providers/base.py
contains the base provider interfaceproviders/openai.py
contains the moved OpenAI implementationproviders/__init__.py
exports the provider functionsTesting
The implementation maintains backward compatibility:
from instructor import from_openai
still works (with deprecation warning)from instructor.providers.openai import from_openai
works without warninginstructor.from_provider("openai/gpt-4")
works correctlyTODO
Future work will involve moving the remaining providers to the new structure:
Link to Devin run
https://app.devin.ai/sessions/8cb6cdfb710c4442a68796becb4d25ec
This PR was requested by Jason Liu (work@jxnl.co)