Metadata-Version: 2.4
Name: multi-ai-handler
Version: 2.1.0
Summary: Unified Python interface for multiple AI providers with support for text, images, and documents.
Project-URL: Homepage, https://github.com/vsharha/multi-ai-handler
Project-URL: Repository, https://github.com/vsharha/multi-ai-handler
Project-URL: Issues, https://github.com/vsharha/multi-ai-handler/issues
Author: Viktor Sharha
License: MIT
License-File: LICENSE
Keywords: ai,anthropic,api,claude,gemini,llm,openai,openrouter
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.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Requires-Dist: anthropic>=0.72.0
Requires-Dist: google-genai>=1.52.0
Requires-Dist: openai>=2.7.1
Requires-Dist: pydantic>=2.0.0
Requires-Dist: python-dotenv>=0.19.0
Requires-Dist: requests>=2.32.5
Provides-Extra: all
Requires-Dist: docling>=2.61.1; extra == 'all'
Requires-Dist: easyocr>=1.7.2; extra == 'all'
Requires-Dist: ollama>=0.6.0; extra == 'all'
Provides-Extra: docling
Requires-Dist: docling>=2.61.1; extra == 'docling'
Requires-Dist: easyocr>=1.7.2; extra == 'docling'
Provides-Extra: local
Requires-Dist: docling>=2.61.1; extra == 'local'
Requires-Dist: easyocr>=1.7.2; extra == 'local'
Requires-Dist: ollama>=0.6.0; extra == 'local'
Provides-Extra: ollama
Requires-Dist: ollama>=0.6.0; extra == 'ollama'
Description-Content-Type: text/markdown

# Multi AI Handler

A unified Python library for interacting with multiple AI providers through a consistent interface. Supports text and file inputs across OpenAI, Anthropic Claude, Google Gemini, OpenRouter, Cerebras and Ollama (local LLMs).

## Features

- Unified interface for multiple AI providers
- **Streaming support** for real-time token output
- **Async support** for concurrent workloads
- Support for images and documents (PDF)
- Local LLM support with Ollama
- Advanced document processing with Docling (OCR, table extraction)
- Model information retrieval

## Installation

```bash
pip install multi-ai-handler
```

**Optional dependencies:**
```bash
pip install multi-ai-handler[ollama]   # Local LLM support
pip install multi-ai-handler[docling]  # Document processing (OCR, tables)
pip install multi-ai-handler[all]      # All optional dependencies
```

## Setup

Create a `.env` file with your API keys:

```env
ANTHROPIC_API_KEY=your_anthropic_api_key_here
CEREBRAS_API_KEY=your_cerebras_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
```

## Usage

### Basic Request

```python
from multi_ai_handler import request_ai

response = request_ai(
    provider="google",  # or "anthropic", "openai", "openrouter", "cerebras", "ollama"
    model="gemini-2.5-flash",
    system_prompt="You are a helpful assistant.",
    user_text="What is the capital of France?"
)
```

### JSON Output

```python
data = request_ai(
    provider="google",
    model="gemini-2.5-flash",
    system_prompt="Return valid JSON only.",
    user_text="Convert to JSON: Name: Alice, Age: 25",
    json_output=True
)
# Returns: {'name': 'Alice', 'age': 25}
```

### File Processing

```python
response = request_ai(
    provider="anthropic",
    model="claude-sonnet-4-5-20250929",
    system_prompt="Summarize this document.",
    file="document.pdf"
)
```

### Streaming

```python
from multi_ai_handler import stream_ai

for chunk in stream_ai(provider="google", model="gemini-2.0-flash", user_text="Write a poem"):
    print(chunk, end="", flush=True)
```

### Async Support

```python
import asyncio
from multi_ai_handler import arequest_ai, astream_ai

async def main():
    # Concurrent requests
    responses = await asyncio.gather(
        arequest_ai(provider="google", model="gemini-2.0-flash", user_text="Hello"),
        arequest_ai(provider="anthropic", model="claude-sonnet-4-20250514", user_text="Hello"),
    )

    # Async streaming
    async for chunk in astream_ai(provider="google", model="gemini-2.0-flash", user_text="Hi"):
        print(chunk, end="", flush=True)

asyncio.run(main())
```

### Model Information

```python
from multi_ai_handler import list_models, get_model_info

all_models = list_models()  # {'google': [...], 'anthropic': [...], ...}
info = get_model_info(provider="google", model="models/gemini-2.0-flash")
```

## API Reference

### Functions

| Function | Description |
|----------|-------------|
| `request_ai(provider, model, ...)` | Generate a response |
| `stream_ai(provider, model, ...)` | Stream response tokens |
| `arequest_ai(provider, model, ...)` | Async generation |
| `astream_ai(provider, model, ...)` | Async streaming |
| `list_models()` | List all available models |
| `get_model_info(provider, model)` | Get model metadata |

### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `provider` | str | `"google"`, `"anthropic"`, `"openai"`, `"openrouter"`, `"cerebras"`, `"ollama"` |
| `model` | str | Model name (e.g., `"gemini-2.5-flash"`, `"claude-sonnet-4-5-20250929"`) |
| `system_prompt` | str | System instruction |
| `user_text` | str | User input text |
| `file` | str/Path | File path for images or documents |
| `temperature` | float | Randomness (0.0-1.0), default: 0.2 |
| `json_output` | bool | Parse response as JSON, default: False |
| `local` | bool | Use local text extraction (Docling), default: False |

### Classes

- `AIProviderManager` - Manage providers, register custom providers
- `AIProvider` - Abstract base class for implementing custom providers
- Provider classes: `AnthropicProvider`, `GoogleProvider`, `OpenAIProvider`, `OpenrouterProvider`, `OllamaProvider`, `CerebrasProvider`

## License

MIT

## Contributing

Contributions are welcome! Please open an issue or submit a pull request.

## Support

For issues and questions, please open an issue on the GitHub repository.

