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
- Copy
.env-exampleto.envand 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:
- Fork the repository.
- Create a branch for your feature or bug fix.
- Update tests and documentation as necessary.
- Run existing tests and pre-commit checks.
- 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!
Metadata
Release files for llm-adapters 8.14.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llm_adapters-8.14.1.tar.gz | 33.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_adapters-8.14.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 89.8 kB
Release files / llm_adapters-8.14.1.tar.gz
| Download URL | llm_adapters-8.14.1.tar.gz |
|---|---|
| Size | 33.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8f3d267dfb495a369ec826fd0d8bc5328d6147f1832e043febc87893b7f60fd
|
|
BLAKE2b-256 checksum How to use checksums |
6a2db679ec117b5fd4e4ffdf6cb8ab4ff79b6f7beb90b34698dd2355dd8abdd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1018-azure
|
Release files / llm_adapters-8.14.1-py3-none-any.whl
| Download URL | llm_adapters-8.14.1-py3-none-any.whl |
|---|---|
| Size | 56.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abed86cdc64b543508b05de6772c7dacd7a5f0e3a25a7194d09fdacbe412b9ac
|
|
BLAKE2b-256 checksum How to use checksums |
ce9e90d8ea086ad1fb60153394fbb6b961adc359309215c323bc79a79e37eeef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1018-azure
|