Metadata-Version: 2.1
Name: martian-adapters
Version: 5.2.0
Summary: Adapters as API gateways to Different LLM Models
Author: Martian team
Author-email: team@withmartian.com
Requires-Python: >=3.11,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: aiohttp (>=3.9.4,<4.0.0)
Requires-Dist: aiolimiter (>=1.1.0,<2.0.0)
Requires-Dist: aiosignal (>=1.3.1,<2.0.0)
Requires-Dist: anthropic (==0.16.0)
Requires-Dist: async-timeout (>=4.0.3,<5.0.0)
Requires-Dist: asyncio (>=3.4.3,<4.0.0)
Requires-Dist: attrs (>=23.1.0,<24.0.0)
Requires-Dist: charset-normalizer (>=3.2.0,<4.0.0)
Requires-Dist: frozenlist (>=1.4.0,<2.0.0)
Requires-Dist: google-generativeai (>=0.3.2,<0.4.0)
Requires-Dist: idna (>=3.7,<4.0)
Requires-Dist: isort (>=5.12.0,<6.0.0)
Requires-Dist: multidict (>=6.0.4,<7.0.0)
Requires-Dist: openai (==1.23.6)
Requires-Dist: pydantic (>=2.4.2,<3.0.0)
Requires-Dist: regex (>=2023.8.8,<2024.0.0)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Requires-Dist: sentencepiece (>=0.1.99,<0.2.0)
Requires-Dist: tiktoken (>=0.5.1,<0.6.0)
Requires-Dist: together (>=0.2.6,<0.3.0)
Requires-Dist: transformers (>=4.36.0,<5.0.0)
Requires-Dist: vcrpy (>=6.0.1,<7.0.0)
Requires-Dist: yarl (>=1.9.2,<2.0.0)
Description-Content-Type: text/markdown

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

## Getting Started

### Prerequisites

- Python version: 3.11.6
- [Poetry](https://python-poetry.org/docs/#installation)

### Installation

1. **Install Python:** Ensure Python `3.11.6` is installed on your system.
2. **Install Poetry:** Follow the installation guide on the [official Poetry website](https://python-poetry.org/docs/#installation).
3. **Install Dependencies:**

   ```bash
   poetry install
   ```

4. **Install Pre-commit Hooks:**

   ```bash
   poetry run pre-commit install
   ```

5. **Run Commands via Poetry:**

   ```bash
   poetry run pytest
   ```

### Setting Up Pre-commit

Pre-commit hooks help maintain code quality and standards. Install them with the following command:

```bash
poetry run pre-commit install
```

To run pre-commit manually:

```bash
poetry run pre-commit run --all-files
```

### Semantic Versioning

For versioning we follow [Semantic Versioning](https://semver.org)

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

```bash
poetry run pytest
```

## Usage

### Creating and Using Adapters

1. **Instantiate an Adapter:**

   ```python
   adapter1 = AdapterFactory.get_adapter_by_path("adapter_path")
   ```

   Here, `"adapter_path"` should follow the format `provider/vendor/model_name`. Use `AdapterFactory.get_supported_models()` to retrieve all supported models. In order to get path to the model use `model.get_path()`

2. **Convert Input:**

   ```python
   adapter1.convert_to_input(prompt)
   ```

3. **Execute Adapter:**

   ```python
   adapter1.execute_async(input_data)
   ```

### Disabling Specific Models

To disable models, set the `ADAPTER_DISABLED_MODELS` environment variable:

```bash
export ADAPTER_DISABLED_MODELS="model1,model2"
```

Disabled models will not appear in the supported models list.

### Retrieving Supported Models

```python
AdapterFactory.get_supported_models()
```

## 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:**

   ```bash
   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.

