Skip to main content

Adapters as API gateways to Different LLM Models

Project description

LLM Adapters Package Documentation

List of currently supported models

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

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

poetry run pytest

Quickstart

from adapters import AdapterFactory

# First component in model path is Provider, then Vendor, and last model name itself
adapter = AdapterFactory.get_adapter_by_path("openai/openai/gpt-4o-mini")

adapter.execute_sync(
    [
        {role: "system", content: "You are a helpful assistant."},
        {
            role: "user",
            content: "Write a haiku about recursion in programming.",
        },
    ]
)

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 MODELS array if the provider is already supported.

  2. New Providers:

    • If the provider follows the OpenAI format, model integration is straightforward. See the "Fireworks" 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 poetry run pytest --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.

Misclenous

HTTP Client configuration

To optimize throughput and performance, we provide options to configure HTTP networking parameters:

ADAPTERS_MAX_KEEPALIVE_CONNECTIONS_PER_PROCESS = 100
ADAPTERS_MAX_CONNECTIONS_PER_PROCESS = 1000
ADAPTERS_HTTP_CONNECT_TIMEOUT = 5
ADAPTERS_HTTP_TIMEOUT = 600

Base URL overriding

For stress testing or other purposes, you can override all base URLs by setting the following in your .env file:

_ADAPTERS_OVERRIDE_ALL_BASE_URLS_ = "https://new-base-url.com/api"

This setting ensures that all LLM API calls will route to the specified new base URL.

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-7.6.2.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

martian_adapters-7.6.2-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: martian_adapters-7.6.2.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0

File hashes

Hashes for martian_adapters-7.6.2.tar.gz
Algorithm Hash digest
SHA256 91d70485b60e4eee89dce7cef3c846fccae0583c2350b85d2df7135f172ddac2
MD5 bfa597d04970417c85be8fbc746dda8c
BLAKE2b-256 0986928d596d5b091d7baaba4d2c7893d9a247656966b815524354ea4935d1fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: martian_adapters-7.6.2-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.3.0

File hashes

Hashes for martian_adapters-7.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0880291e4018b1eaf0b5e33f59f73e98de60f8c16df7e4a27f0d3ed95d672857
MD5 8cc70c74b2ff1cd1657444826977b9a5
BLAKE2b-256 77fd6d91b61de7083cba7c5c2cda286554d90556d09ca65e0dacdb26bd5536c9

See more details on using hashes here.

Supported by

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