Skip to main content

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

  1. Existing Providers: Add new models to the SUPPORTED_MODELS array if the provider is already supported.

  2. 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

  1. Add the Provider and Model: Update provider_adapters/__init__.py and test files accordingly.

  2. Write Tests: Add tests in the relevant directories. Use @pytest.mark.vcr for tests making network requests.

  3. Run Tests:

    poetry run pytest
    
  4. Check-in Cassette Files: Include any new cassette YAML files in your commit.

  5. 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

martian_adapters-6.6.1.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

martian_adapters-6.6.1-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

Details for the file martian_adapters-6.6.1.tar.gz.

File metadata

  • Download URL: martian_adapters-6.6.1.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Darwin/24.0.0

File hashes

Hashes for martian_adapters-6.6.1.tar.gz
Algorithm Hash digest
SHA256 6cd02ba9d61ca42ad8c75972433a19baeac5008e6c1750dbba124cb5e4ced064
MD5 8185d5ba6b718701bb425b347a12fc69
BLAKE2b-256 0e9340a04180a070b99ea4b309cf43d9f60fd123ec85e6056fd044b090076b66

See more details on using hashes here.

File details

Details for the file martian_adapters-6.6.1-py3-none-any.whl.

File metadata

  • Download URL: martian_adapters-6.6.1-py3-none-any.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Darwin/24.0.0

File hashes

Hashes for martian_adapters-6.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b8a73e260001811377b8a9384419c8181c59dbb8403e3bf1f63ff86d90b161b
MD5 fa3e10325b89d5c9fc489df03ab1c1f4
BLAKE2b-256 77fdd944a499d02313d6755dbbf5856721f1d42fb882d067dde3cd785581ac0d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page