Skip to main content

Adapters as API gateways to Different LLM Models

Project description

LLM Adapters

LLM Adapters provides a unified interface for interacting with various language model APIs, supporting both synchronous and asynchronous operations. Whether you're using OpenAI, Claude, or other providers, this library simplifies integration and offers flexibility in usage.

Installation

To install llm-adapters for use in your projects, simply run:

pip install llm-adapters

Usage

Package is using OpenAI SDK format, so you can use it as a drop in replacement for the OpenAI SDK, just need to change the import. It works both for synchronous and asynchronous clients.

from llm_adapters import OpenAI

client = OpenAI()

completion = client.chat.completions.create(
  model="claude-3-5-sonnet-20241022",
  messages=[
    {"role": "developer", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

Note: If you plan to contribute to this project, you'll need Poetry to set up the development environment. After cloning the repository, run:

poetry install
poetry run pre-commit install

Getting Started

Prerequisites

  • Python 3.11+
  • Poetry (if using Poetry)

Setup

  1. Copy .env-example to .env and fill in the necessary environment variables.

Supported Models

Adapter paths follow the format provider/vendor/model_name. Use AdapterFactory.get_supported_models() to retrieve all supported models. For any model, calling .get_path() will return its adapter path.

Configuration and Environment

LLM Adapters can be customized via environment variables. For example, configure the HTTP client settings with:

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

To override base URLs for testing or specific setups:

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

Testing and Pre-commit

  • Run tests with:
poetry run pytest
  • Validate code using pre-commit hooks:
poetry run pre-commit run --all-files

Contributing

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a branch for your feature or bug fix.
  3. Update tests and documentation as necessary.
  4. Run existing tests and pre-commit checks.
  5. Submit a pull request.

Versioning

This project adheres to Semantic Versioning.

Additional Resources

For complete documentation and a list of supported models, please visit our Documentation Site.

Happy coding!

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

llm_adapters-8.3.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

llm_adapters-8.3.0-py3-none-any.whl (54.5 kB view details)

Uploaded Python 3

File details

Details for the file llm_adapters-8.3.0.tar.gz.

File metadata

  • Download URL: llm_adapters-8.3.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for llm_adapters-8.3.0.tar.gz
Algorithm Hash digest
SHA256 684915bf240cca163b7c5b2d44aa6f2999ab6f8c9d434f48c2131c70902296ce
MD5 48b256c712f2a6225ebbabaa0b51ff41
BLAKE2b-256 3067ca0b4dadac5931e58b27869dc0af6c8c6533e6a637db99585ef4334ea3fb

See more details on using hashes here.

File details

Details for the file llm_adapters-8.3.0-py3-none-any.whl.

File metadata

  • Download URL: llm_adapters-8.3.0-py3-none-any.whl
  • Upload date:
  • Size: 54.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for llm_adapters-8.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff107fdb5a4fb8b7c73dc4a4d63da52135375a6672b925045b74bf76d832ca1e
MD5 85d5a0e81589070128d4ae9a9e4c09ac
BLAKE2b-256 e34fc5e4152fc5c412a5928e875f81d699c4c53194c95b3f4ade29ecee9a1d08

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