Skip to main content

Composo Python SDK

Project description

Composo Python SDK

A Python SDK for Composo evaluation services, providing both synchronous and asynchronous clients for evaluating LLM conversations using simple dictionary message formats, with support for results from various LLM providers.

Features

  • Dual Client Support: Both synchronous and asynchronous clients
  • Simple Message Format: Easy-to-use dictionary format for messages
  • LLM Result Support: Compatible with results from OpenAI, Anthropic, and other providers
  • 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

pip install composo

Quick Start

Basic Usage

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

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

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)

Logging

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

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

Error Handling

The SDK provides specific exception types:

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

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

composo-0.2.17.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

composo-0.2.17-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file composo-0.2.17.tar.gz.

File metadata

  • Download URL: composo-0.2.17.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for composo-0.2.17.tar.gz
Algorithm Hash digest
SHA256 5ec30948532d0a93f7639c5bcd7d1bffa14c4baa2a5412cd810ef1f796bb1d6e
MD5 9af312972dd3c89875b664d15f16c406
BLAKE2b-256 9ba40eaa7adf83177b58aca391f7369e7dd8dc631a1b9d94536fe53d5e3cebd9

See more details on using hashes here.

File details

Details for the file composo-0.2.17-py3-none-any.whl.

File metadata

  • Download URL: composo-0.2.17-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for composo-0.2.17-py3-none-any.whl
Algorithm Hash digest
SHA256 512402b4f51887909f25adfb4dc9984d8c0f7beaf3043c14ddb55ac08edbca69
MD5 b1e512d56f5db84bb3cfa4ad4321d85f
BLAKE2b-256 dfeecd0cd33402cd96a0019f45b668a13932ac812e1f0a55e30cd36ecf0ed5e6

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