Skip to main content

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 logic
  • core/: Core business logic (models, inference, optimization)
  • loaders/: Data loaders for models, prompts, and contexts
  • cli/: Command-line interface using Fire and Rich
  • utils/: Shared utilities

Dependencies

  • pydantic: Data validation and settings management
  • litellm: Unified LLM API interface
  • rich: Terminal formatting and progress bars
  • fire: CLI framework
  • tenacity: Retry logic
  • loguru: Advanced logging
  • tiktoken: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmstrix-1.0.11.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmstrix-1.0.11-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

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

Hashes for lmstrix-1.0.11.tar.gz
Algorithm Hash digest
SHA256 0255ff94144d176d494b73db7f95bb3a3582804b0e5234ed73399e9f0bf463fa
MD5 baac024960a98f0e380a1f2d9953c2fb
BLAKE2b-256 8527dbf0d1409af899efc529f87d54eda18a032cc64ce992aa309e39092becb8

See more details on using hashes here.

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

Hashes for lmstrix-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a167767d2d1d915fec73763006b26b8101388cacaba662bd2d50072274803c71
MD5 fb9d53c71889e248e62055f31ad8ad04
BLAKE2b-256 c6ad370639367c687d23741c9d7210ba3230a636cd9da13c6debb0ad55fbcf22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page