Metadata-Version: 2.4
Name: llm-unity
Version: 0.1.0
Summary: Unified interface for interacting with multiple LLM providers.
Project-URL: Repository, https://github.com/jgmagarino/llm-unity
Project-URL: Issues, https://github.com/jgmagarino/llm-unity/issues
Author: jgmagarino
License-Expression: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.12
Requires-Dist: httpx>=0.28.1
Description-Content-Type: text/markdown

# LLM-Unity

**LLM-Unity** is a Python library that provides a unified interface for interacting with multiple Large Language Model (LLM) providers.

The goal of the project is to allow applications to work with different LLM providers using the same interface, reducing the need to adapt application code whenever the underlying provider changes.

## Supported Providers

Currently supported providers:

* **Ollama**
* **OpenRouter**
* **Google AI Studio**

The library supports both synchronous and asynchronous generation, as well as streaming responses.

## Installation

Install LLM-Unity using pip:

```bash
pip install llm-unity
```

LLM-Unity requires Python 3.12 or newer.

## Basic Usage

Each provider is configured using its corresponding configuration class and then created through `create_provider()`.

For example, using Google AI Studio:

```python
import os

from llm_unity import create_provider
from llm_unity.config import GoogleAIStudioConfig


config = GoogleAIStudioConfig(
    model_name=os.getenv("GOOGLE_AI_STUDIO_MODEL", ""),
    api_key=os.getenv("GOOGLE_AI_STUDIO_API_KEY", ""),
    timeout=300,
)

provider = create_provider(config)

response = provider.generate(
    "Explain the difference between Python and Java."
)

print(response.text)
```

The same general approach can be used with the other supported providers by changing the configuration class.

## Async Usage

LLM-Unity also provides asynchronous methods:

```python
response = await provider.a_generate(
    "Explain the difference between Python and Java."
)

print(response.text)
```

## Streaming

Responses can also be streamed incrementally.

```python
async for chunk in provider.a_stream(
    "Tell me about the beginning of artificial intelligence."
):
    print(chunk.text, end="")
```

This allows applications to process and display the generated text as it becomes available instead of waiting for the complete response.

## Response Model

LLM-Unity normalizes provider responses into a common `Response` model.

A response can contain the generated text as well as additional information about the request and the model that generated it.

For example:

```python
response = provider.generate(
    "Explain what machine learning is."
)

print(response.text)
```

Conceptually, a response can contain information similar to:

```python
Response(
    text="Machine learning is a branch of artificial intelligence...",
    model="some-model",
    provider="some-provider",
    response_time=1.42,
)
```

The exact metadata available depends on the information provided by the underlying LLM provider.

The purpose of this common response model is to provide applications with a consistent structure regardless of which provider is being used.

## Environment Variables

API keys should not be hard-coded into applications.

For example:

```env
GOOGLE_AI_STUDIO_API_KEY=your-api-key
GOOGLE_AI_STUDIO_MODEL=your-model
```

The `.env` file is only an example of how credentials can be managed. LLM-Unity itself does not require `python-dotenv`; applications are free to use whatever configuration mechanism they prefer.

## Project Status

LLM-Unity is currently in **Alpha** (`0.1.0`).

The project is still evolving, and its API may change in future versions.

Feedback, bug reports, and suggestions are welcome through the project's GitHub repository.

## License

LLM-Unity is released under the **MIT License**.

## Repository

https://github.com/jgmagarino/llm-unity
