Giskard LLM Utils
A Python library providing utility functions and tools for working with Large Language Models (LLMs). This library is part of the Giskard ecosystem and provides various utilities for LLM operations, including model management, clustering, and more.
Purpose
This library aims to simplify working with LLMs by providing:
- A unified interface for different LLM providers through LiteLLM
- Support for both cloud-based and local embedding models
- Easy configuration through environment variables or direct initialization
- Synchronous and asynchronous operations for better performance
Installation
Standard Installation
pip install giskard-lmutils
Local Embedding Support
For local embedding capabilities, install with the local-embedding extra:
pip install "giskard-lmutils[local-embedding]"
This will install the required dependencies (torch and transformers) for running embedding models locally.
Development Installation
- Install python, UV and make
- Clone this repository
- Setup the virtual environment using
make setup
Using LiteLLMModel
The LiteLLMModel class provides a unified interface for working with various LLM providers through the LiteLLM library. It supports both completion and embedding operations, with both synchronous and asynchronous methods.
Configuration
You can configure the model in two ways:
- Through environment variables:
# Required for OpenAI models
export OPENAI_API_KEY="your-api-key"
# Model configuration
export GSK_COMPLETION_MODEL="gpt-3.5-turbo"
export GSK_EMBEDDING_MODEL="text-embedding-ada-002"
from giskard_lmutils.model import LiteLLMModel
# This will use environment variables for model names
model = LiteLLMModel(
completion_params={"temperature": 0.7},
embedding_params={"is_local": False} # Optional, defaults to False
)
Note: The environment variable prefix can be customized by passing an env_prefix parameter to the LiteLLMModel initialization. This allows you to use different models within the same application by setting different environment variables (e.g., CUSTOM_PREFIX_COMPLETION_MODEL).
- Through specified model names:
model = LiteLLMModel(
completion_model="gpt-3.5-turbo",
embedding_model="text-embedding-ada-002",
completion_params={"temperature": 0.7},
embedding_params={"is_local": False} # Optional, defaults to False
)
Note: When using OpenAI models, you must set the OPENAI_API_KEY environment variable. For other providers, refer to the LiteLLM documentation for their specific API key requirements.
Usage Examples
Text Completion
# Synchronous completion
response = model.complete([
{"role": "user", "content": "What is the capital of France?"}
])
# Asynchronous completion
response = await model.acomplete([
{"role": "user", "content": "What is the capital of France?"}
])
Text Embedding
# Synchronous embedding
embeddings = model.embed(["Hello, world!", "Another text"])
# Asynchronous embedding
embeddings = await model.aembed(["Hello, world!", "Another text"])
# Local embedding
model = LiteLLMModel(
embedding_model="sentence-transformers/all-MiniLM-L6-v2",
embedding_params={"is_local": True}
)
embeddings = model.embed(["Hello, world!"])
Requirements
- Python >= 3.9, < 3.14
- Core dependencies:
- numpy >= 2.2.2
- litellm >= 1.59.3
- Optional dependencies (for local embedding):
- torch >= 2.6.0
- transformers >= 4.51.3
License
This project is licensed under the Apache Software License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Authors
- Kevin Messiaen (kevin@giskard.ai)
Metadata
Release files for giskard-lmutils 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| giskard_lmutils-1.0.0.tar.gz | 116.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| giskard_lmutils-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 126.8 kB
Release files / giskard_lmutils-1.0.0.tar.gz
| Download URL | giskard_lmutils-1.0.0.tar.gz |
|---|---|
| Size | 116.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
442fbf647ed1961770c8b962ab48321663302214c75ceb8fae7a71adcd3a003d
|
|
BLAKE2b-256 checksum How to use checksums |
b14e656251a59dc53e24a0fca708e3d8fb5d451cbea4bbeedc371b9c8e0e0f24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / giskard_lmutils-1.0.0-py3-none-any.whl
| Download URL | giskard_lmutils-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc07f1a0f16a0f4bf982751380332570b83170c5d53f8c912c070df5fe17ecb2
|
|
BLAKE2b-256 checksum How to use checksums |
138d9dac642cdcc12b35fe54c32b19cee189cae4a1a67fb9d4d74dacf2f4f53a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for giskard-lmutils 1.0.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.