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

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


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_wyzerstudio-7.0.0a2.tar.gz (35.8 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_wyzerstudio-7.0.0a2-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

Details for the file martian_adapters_wyzerstudio-7.0.0a2.tar.gz.

File metadata

File hashes

Hashes for martian_adapters_wyzerstudio-7.0.0a2.tar.gz
Algorithm Hash digest
SHA256 dc6b0da8b749a9ce911f4771610b40c46bef06c7404859eb2200a42a45b8b1ca
MD5 f4d8b90c13b4eff57d415eca166ed5a4
BLAKE2b-256 1811b906729aa3748758355f7c47e64d587e6ba4e6e103d55bd358eb46d2427e

See more details on using hashes here.

File details

Details for the file martian_adapters_wyzerstudio-7.0.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for martian_adapters_wyzerstudio-7.0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 d388247cca146ecf62f9a5baecf1466b831a8e782815c4ec14c1d07e71aafaaf
MD5 98ff5c3ae24cc603cc991b6817976c31
BLAKE2b-256 7ccafb36195e22b29f37663d8ff8de3f25ad3d4106f3b27486fe9e7796b9684c

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