A toolkit for managing and testing LM Studio models with automatic context limit discovery
Project description
LMStrix
A professional, installable PyPI package for managing and utilizing models with LM Studio.
Overview
LMStrix is a robust toolkit that provides seamless integration with LM Studio's local server, enabling efficient model management and inference. The standout feature is the Adaptive Context Optimizer, which automatically determines the maximum operational context length for any given model, eliminating the need for manual tuning.
Key Features
- Model Management: Easily discover, list, and manage LM Studio models
- Adaptive Context Optimization: Automatically find the optimal context window for each model using binary search
- Flexible Inference Engine: Run inference with customizable prompts and context management
- Two-Phase Prompt Resolution: Advanced templating system with placeholder resolution
- Rich CLI: Beautiful command-line interface with formatted tables and progress indicators
- Async-First Design: Built on modern async/await patterns for optimal performance
- Robust Error Handling: Comprehensive exception hierarchy and retry logic
Installation
pip install lmstrix
Quick Start
Command Line Interface
# List available models
lmstrix models list
# Scan for new models
lmstrix models scan
# Run inference
lmstrix infer --model "llama-3.1" --prompt "greeting"
# Optimize a model's context window
lmstrix optimize llama-3.1
Python API
from lmstrix import LMStrix
# Initialize client
client = LMStrix()
# List models
models = await client.list_models()
for model in models:
print(f"{model.id}: {model.context_limit} tokens")
# Run inference
result = await client.infer(
model_id="llama-3.1",
prompt_template="Summarize this text: {text}",
context={"text": "Your long document here..."}
)
print(result.content)
# Optimize context window
optimization = await client.optimize_context("llama-3.1")
print(f"Optimal context: {optimization.optimal_size} tokens")
Architecture
LMStrix is organized into modular components:
api/: LM Studio API client with retry logiccore/: Core business logic (models, inference, optimization)loaders/: Data loaders for models, prompts, and contextscli/: Command-line interface using Fire and Richutils/: Shared utilities
Dependencies
pydantic: Data validation and settings managementlitellm: Unified LLM API interfacerich: Terminal formatting and progress barsfire: CLI frameworktenacity: Retry logicloguru: Advanced loggingtiktoken: Token counting
Development
# Install in development mode
pip install -e .
# Run tests
python -m pytest
# Format code
python -m ruff format src/
# Check linting
python -m ruff check src/
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
Support
For issues, feature requests, or questions, please file an issue on our GitHub repository.
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
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 lmstrix-1.0.11.tar.gz.
File metadata
- Download URL: lmstrix-1.0.11.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0255ff94144d176d494b73db7f95bb3a3582804b0e5234ed73399e9f0bf463fa
|
|
| MD5 |
baac024960a98f0e380a1f2d9953c2fb
|
|
| BLAKE2b-256 |
8527dbf0d1409af899efc529f87d54eda18a032cc64ce992aa309e39092becb8
|
File details
Details for the file lmstrix-1.0.11-py3-none-any.whl.
File metadata
- Download URL: lmstrix-1.0.11-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a167767d2d1d915fec73763006b26b8101388cacaba662bd2d50072274803c71
|
|
| MD5 |
fb9d53c71889e248e62055f31ad8ad04
|
|
| BLAKE2b-256 |
c6ad370639367c687d23741c9d7210ba3230a636cd9da13c6debb0ad55fbcf22
|