A lightweight library for LLM model names and support definitions.
Project description
LLM Relic
A lightweight Python library that provides easy access to popular LLM model names and allows you to define which models your application supports.
Why LLM Relic?
- No more hardcoded model names: Access standardized model names from major providers
- Easy support definition: Fluent interface to define which models your app supports
- Validation: Built-in validation to ensure only supported models are used
- Zero dependencies: Lightweight library with no external dependencies
- Type hints: Full type hint support for better IDE experience
Installation
pip install llmrelic
Quick Start
Access Model Names
from llmrelic import OpenAI, Anthropic, Google
# Access model names directly
print(OpenAI.gpt_4) # "gpt-4"
print(Anthropic.claude_3_opus) # "claude-3-opus-20240229"
print(Google.gemini_pro) # "gemini-pro"
# List all models from a provider
print(OpenAI.list_models())
Define Supported Models
from llmrelic import SupportedModels
# Define which models your app supports
supported = (SupportedModels.create()
.openai() # All OpenAI models
.anthropic(["claude-3-opus-20240229", "claude-3-sonnet-20240229"]) # Specific models
.google() # All Google models
.custom(["my-custom-model"]) # Your custom models
.build())
# Validate model support
if supported.is_supported("gpt-4"):
print("GPT-4 is supported!")
# Get all supported models
print(supported.get_supported_models())
Use in Your Application
from llmrelic import OpenAI, SupportedModels
class MyLLMApp:
def __init__(self):
# Define what models your app supports
self.supported_models = (SupportedModels.create()
.openai(["gpt-4", "gpt-3.5-turbo"])
.anthropic()
.build())
def chat(self, model_name: str, message: str):
if not self.supported_models.is_supported(model_name):
available = ", ".join(self.supported_models.get_supported_models())
raise ValueError(f"Model {model_name} not supported. Available: {available}")
# Your chat logic here
return f"Response from {model_name}"
# Usage
app = MyLLMApp()
app.chat(OpenAI.gpt_4, "Hello!") # Works
app.chat("gpt-4", "Hello!") # Works
# app.chat("unsupported-model", "Hello!") # Raises ValueError
Supported Providers
- OpenAI: GPT-4, GPT-3.5-turbo, and more
- Anthropic: Claude 3 Opus, Sonnet, Haiku, and more
- Google: Gemini Pro, Bard, PaLM-2, and more
- Cohere: Command, Command-Light, Command-R, and more
- Mistral: Mistral 7B, Mixtral 8x7B, and more
- Meta: Llama 2, Code Llama, and more
- Hugging Face: Popular open-source models
API Reference
Model Providers
Each provider exposes models as attributes:
from llmrelic import OpenAI, Anthropic, Google, Cohere, Mistral, Meta, Huggingface
# Access models
OpenAI.gpt_4 # "gpt-4"
Anthropic.claude_3_opus # "claude-3-opus-20240229"
Google.gemini_pro # "gemini-pro"
# List all models
OpenAI.list_models()
# Check if model exists
"gpt-4" in OpenAI # True
SupportedModels (Fluent Interface)
from llmrelic import SupportedModels
supported = (SupportedModels.create()
.openai() # All OpenAI models
.openai(["gpt-4", "gpt-3.5-turbo"]) # Specific OpenAI models
.anthropic() # All Anthropic models
.google(["gemini-pro"]) # Specific Google models
.custom(["my-model"]) # Custom models
.build())
# Check support
supported.is_supported("gpt-4") # True
# Get models
supported.get_models() # List of all supported models
ModelRegistry (Direct Interface)
from llmrelic import ModelRegistry
registry = ModelRegistry()
registry.add_provider("openai")
registry.add_models(["custom-model-1", "custom-model-2"])
registry.add_model("another-model")
# Check support
registry.is_supported("gpt-4") # True
"gpt-4" in registry # True
# Get models
registry.get_supported_models()
registry.get_supported_by_provider()
# Iterate
for model in registry:
print(model)
Utility Functions
from llmrelic import get_all_models, find_model
# Get all available models by provider
all_models = get_all_models()
# Find which provider a model belongs to
provider = find_model("gpt-4") # "openai"
Contributing
- Fork the repository
- Create a feature branch
- Add your changes
- Run tests:
pytest - Submit a pull request
License
MIT License
Changelog
0.1.0
- Initial release
- Basic model name access
- Fluent interface for defining supported models
- Model validation and registry functionality
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
llmrelic-0.1.0.tar.gz
(3.6 kB
view details)
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 llmrelic-0.1.0.tar.gz.
File metadata
- Download URL: llmrelic-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f245e589af3e71701a80c113c3436adf3582443e6156dec8c84304370cdb76e5
|
|
| MD5 |
9fa86bb22578ed4f50a3c13c235f5c34
|
|
| BLAKE2b-256 |
862b677bfa5b1a5be58bb00664b08134ad80c13deaa47328364029badd3434c8
|
File details
Details for the file llmrelic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llmrelic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6862051607c3ac72e1fd0515b6f470b7fead6a83a90524d7a35e2e6403c63bc
|
|
| MD5 |
6665d1c901401be7be00997c106fe127
|
|
| BLAKE2b-256 |
17280abee519fb0436387330c66b164a728d468348d486661c4f312dbe9a73a9
|