Metadata-Version: 2.4
Name: composo
Version: 0.0.12
Summary: Composo Python SDK
Author-email: Your Name <your.email@example.com>
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.21.0
Requires-Dist: pydantic<3.0.0,>=1.9.2
Requires-Dist: typing-extensions>=4.0.0
Requires-Dist: deepdiff>=6.0.0
Requires-Dist: openai>=1.0.0
Requires-Dist: anthropic>=0.25.0
Requires-Dist: tenacity>=8.0.0
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"

# Composo Python SDK

A Python SDK for Composo evaluation services, providing both synchronous and asynchronous clients for evaluating LLM conversations with support for OpenAI and Anthropic formats.

## Features

- **Dual Client Support**: Both synchronous and asynchronous clients
- **Multiple LLM Provider Support**: Native support for OpenAI and Anthropic formats
- **Connection Pooling**: Optimized HTTP client with connection reuse
- **Retry Logic**: Exponential backoff with jitter for robust API calls
- **Type Safety**: Full type hints and Pydantic models
- **Context Managers**: Proper resource management with context managers

## Installation

```bash
pip install composo
```

## Quick Start

### Basic Usage

```python
from composo import Composo, AsyncComposo

# Initialize client
client = Composo(api_key="your-api-key")

# Evaluate messages
messages = [
    {"role": "user", "content": "What is machine learning?"},
    {"role": "assistant", "content": "Machine learning is..."}
]

criteria = ["Reward responses that provide accurate technical explanations"]

result = client.evaluate(messages=messages, criteria=criteria)
print(f"Score: {result.score}")
print(f"Explanation: {result.explanation}")
```

### Async Usage

```python
import asyncio
from composo import AsyncComposo

async def main():
    async with AsyncComposo(api_key="your-api-key") as client:
        result = await client.evaluate(
            messages=messages,
            criteria=criteria
        )
        print(f"Score: {result.score}")

asyncio.run(main())
```

### With LLM Results

```python
import openai
from composo import Composo

# Get response from OpenAI
openai_client = openai.OpenAI(api_key="your-openai-key")
openai_result = openai_client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "What is machine learning?"}]
)

# Evaluate the response
composo_client = Composo(api_key="your-composo-key")
eval_result = composo_client.evaluate(
    messages=[{"role": "user", "content": "What is machine learning?"}],
    result=openai_result,
    criteria=["Reward accurate technical explanations"]
)
```

## Configuration

### Client Options

- `api_key` (required): Your Composo API key
- `base_url` (optional): Custom API endpoint (default: https://platform.composo.ai)
- `num_retries` (optional): Number of retry attempts (default: 1)
- `model_core` (optional): Specific model core for evaluation

### Logging

The SDK uses Python's standard logging module. Configure logging level:

```python
import logging
logging.getLogger("composo").setLevel(logging.INFO)
```

## Error Handling

The SDK provides specific exception types:

```python
from composo import (
    ComposoError,
    RateLimitError,
    MalformedError,
    APIError,
    AuthenticationError
)

try:
    result = client.evaluate(messages=messages, criteria=criteria)
except RateLimitError:
    print("Rate limit exceeded")
except AuthenticationError:
    print("Invalid API key")
except ComposoError as e:
    print(f"Composo error: {e}")
```

## Performance Optimization

- **Connection Pooling**: HTTP clients reuse connections for better performance
- **Context Managers**: Use context managers to properly close connections
- **Async Support**: Use async client for high-throughput scenarios
