Adapters as API gateways to Different LLM Models
Project description
Adapters Package Documentation
Overview
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
Getting Started
Prerequisites
- Python version: 3.11.10
- Poetry
Installation
poetry install
poetry run pre-commit install
Setting Up Pre-commit
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
Semantic Versioning
For versioning we follow Semantic Versioning
Environment Configuration
The package requires certain environment variables to be set by the users:
- Copy
.env-example
to.env
and populate it with appropriate values.
Running Tests
Ensure Python 3.11 is used:
poetry run pytest
Quickstart
from adapters import AdapterFactory, Prompt
from adapters.types import Conversation, ConversationRole, Turn
adapter = AdapterFactory.get_adapter_by_path("openai/openai/gpt-4o-mini")
conversation = Conversation(
[Turn(role=ConversationRole.user, content="Hi")]
)
adapter.execute_sync(conversation)
Adapter paths follows the format provider/vendor/model_name
. Use AdapterFactory.get_supported_models()
to retrieve all supported models. For a given model, model.get_path()
returns the adapter path.
Contributing
Adding New 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.
Development Steps
-
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.
Re-creating Cassette Files
Use the --record-mode=rewrite
option with pytest to update cassette files.
Additional Notes
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file martian_adapters-6.5.3.tar.gz
.
File metadata
- Download URL: martian_adapters-6.5.3.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1057-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c3cc2596fdfef9e1a7e2939230df6d4579e8f25ff25f7702f7131b6d72887a4 |
|
MD5 | 5e5cd00390a23271292237ca58fe5281 |
|
BLAKE2b-256 | 1cf0074db14a57c3f57aabd8608b3150e914949b1d4d8ad4e48f0ba2c92f756c |
File details
Details for the file martian_adapters-6.5.3-py3-none-any.whl
.
File metadata
- Download URL: martian_adapters-6.5.3-py3-none-any.whl
- Upload date:
- Size: 51.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1057-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 785f72c76d4815ee0da05c6488dc6dc0457f1fb2f4d20edf621aa4c54e9b0987 |
|
MD5 | e3796904f84ba2cb643d7f809468ff13 |
|
BLAKE2b-256 | 42202d097fa855d33764fdeb61ae07d9c824fd2493052218d9a63aebd3d5097e |