The Adapters package facilitates communication between different language model APIs by providing a unified interface for interaction. This ensures ease of use and flexibility in integrating multiple models from various providers.
The package can be installed an used via pip:
pip install martian-adapters
- Python version: 3.11.6
- Poetry
-
Install Python: Ensure Python
3.11.6
is installed on your system. -
Install Poetry: Follow the installation guide on the official Poetry website.
-
Install Dependencies:
poetry install
-
Install Pre-commit Hooks:
poetry run pre-commit install
-
Run Commands via Poetry:
poetry run pytest
Pre-commit hooks help maintain code quality and standards. Install them with the following command:
poetry run pre-commit install
To run pre-commit manually:
poetry run pre-commit run --all-files
For versioning we follow Semantic Versioning
The package requires certain environment variables to be set by the users:
- Copy
.env-example
to.env
and populate it with appropriate values.
Ensure Python 3.11 is used:
poetry run pytest
-
Instantiate an Adapter:
adapter1 = AdapterFactory.get_adapter_by_path("adapter_path")
Here,
"adapter_path"
should follow the formatprovider/vendor/model_name
. UseAdapterFactory.get_supported_models()
to retrieve all supported models. In order to get path to the model usemodel.get_path()
-
Convert Input:
adapter1.convert_to_input(prompt)
-
Execute Adapter:
adapter1.execute_async(input_data)
To disable models, set the ADAPTER_DISABLED_MODELS
environment variable:
export ADAPTER_DISABLED_MODELS="model1,model2"
Disabled models will not appear in the supported models list.
AdapterFactory.get_supported_models()
-
Existing Providers: Add new models to the
SUPPORTED_MODELS
array if the provider is already supported. -
New Providers:
- If the provider follows the OpenAI format, model integration is straightforward. See the "Together" provider class as an example.
- For providers with different schemas, see the "Anthropic" provider class for guidance.
-
Add the Provider and Model: Update
provider_adapters/__init__.py
and test files accordingly. -
Write Tests: Add tests in the relevant directories. Use
@pytest.mark.vcr
for tests making network requests. -
Run Tests:
poetry run pytest
-
Check-in Cassette Files: Include any new cassette YAML files in your commit.
-
Send a Pull Request: Ensure all tests pass before requesting a review.
Use the --record-mode=rewrite
option with pytest to update cassette files.
Some models may only be accessible from specific locations (e.g., the U.S.). In such cases, running tests might require access to a U.S.-based server.
This documentation provides a streamlined approach to using and contributing to the Adapters package, emphasizing practical steps and clear examples.