Skip to main content

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:

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:

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:

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

print(response.text)

Streaming

Responses can also be streamed incrementally.

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:

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

print(response.text)

Conceptually, a response can contain information similar to:

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:

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

Metadata

Release files for llm-unity 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-unity 0.1.0
File Size Uploaded Provenance Actions
llm_unity-0.1.0.tar.gz 31.1 kB Without provenance Details for llm_unity-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-unity 0.1.0
File Interpreter ABI Platform Actions
llm_unity-0.1.0-py3-none-any.whl Python 3 none any Details for llm_unity-0.1.0-py3-none-any.whl

Total release size: 45.0 kB

Release files / llm_unity-0.1.0.tar.gz

Download URL llm_unity-0.1.0.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
227b5cbb443665cfe0619d70af86a1420d24f6cbcc8e8e050a0a96ea54308ca1
BLAKE2b-256 checksum
How to use checksums
a180b3a32253e630308f63c54721d1e1ab242064f9fb358672701ab88c9877de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / llm_unity-0.1.0-py3-none-any.whl

Download URL llm_unity-0.1.0-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d444df1d9f6693827b3edf002144b1785a5adc0723bf9e6fe587bb4c22110dd
BLAKE2b-256 checksum
How to use checksums
104716122ced91dec4f0adfaf8b62ca2e268462d8f4fff28d6bdcf870657d0b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for llm-unity 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page