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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_unity-0.1.0.tar.gz.
File metadata
- Download URL: llm_unity-0.1.0.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
227b5cbb443665cfe0619d70af86a1420d24f6cbcc8e8e050a0a96ea54308ca1
|
|
| MD5 |
7e64c929c2c398e05a40f513375ef0e2
|
|
| BLAKE2b-256 |
a180b3a32253e630308f63c54721d1e1ab242064f9fb358672701ab88c9877de
|
File details
Details for the file llm_unity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_unity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d444df1d9f6693827b3edf002144b1785a5adc0723bf9e6fe587bb4c22110dd
|
|
| MD5 |
b11b298202c06990d52a2d13cfdb227b
|
|
| BLAKE2b-256 |
104716122ced91dec4f0adfaf8b62ca2e268462d8f4fff28d6bdcf870657d0b1
|