Skip to main content

Convert Large Language Models to Small Language Models with CLI, Web UI, and IDE integration

Project description

llm2slm

Python Version PyPI Version Docker Image License CI/CD Coverage

A robust Python library and CLI tool for converting Large Language Models (LLMs) to optimized Small Language Models (SLMs). Streamline model deployment with provider integrations, containerization, and API access.

A robust Python library and CLI tool for converting Large Language Models (LLMs) to optimized Small Language Models (SLMs). Streamline model deployment with provider integrations, containerization, and API access.

Features

  • CLI Interface: Command-line tools for seamless model conversion and management.
  • Provider Integrations: Support for OpenAI, Anthropic, Google Gemini, and LiquidAI providers.
  • Server API: FastAPI-based REST API for remote model operations.
  • Docker Support: Containerized deployment for easy scaling.
  • CI/CD Pipelines: Automated testing and deployment via GitHub Actions.
  • Comprehensive Testing: High-coverage pytest suite with type hints and docstrings.
  • Error Handling & Logging: Robust logging and exception management.
  • Semantic Versioning: Predictable release cycles.

Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)

Install from PyPI

pip install llm2slm

Install from Source

git clone https://github.com/Kolerr-Lab/llm2slm-oss.git
cd llm2slm
pip install -e .

Docker Installation

docker build -t llm2slm .
docker run -p 8000:8000 llm2slm

Usage

CLI

Show version:

llm2slm version

List available providers:

llm2slm providers

Validate setup:

llm2slm validate

Convert an LLM to SLM:

# Using OpenAI (default)
llm2slm convert openai/gpt-4 ./my-slm --provider openai --compression-factor 0.5

# Using Anthropic Claude
llm2slm convert claude-3-opus-20240229 ./my-slm --provider anthropic --compression-factor 0.5

# Using Google Gemini
llm2slm convert gemini-pro ./my-slm --provider google --compression-factor 0.5

# Using LiquidAI
llm2slm convert liquid-1.0 ./my-slm --provider liquid --compression-factor 0.5

API Server

Start the server:

llm2slm serve --host 0.0.0.0 --port 8000

Example API request:

curl -X POST "http://localhost:8000/convert" \
    -H "Content-Type: application/json" \
    -d '{"model": "openai/gpt-4", "output": "my-slm"}'

Python Library

from llm2slm import convert_model

# Convert a model using OpenAI
result = await convert_model(
    input_model="openai/gpt-4",
    output_path="./my-slm",
    provider="openai",
    compression_factor=0.5
)

# Convert using Anthropic
result = await convert_model(
    input_model="claude-3-opus-20240229",
    output_path="./my-slm",
    provider="anthropic",
    compression_factor=0.5
)

# Convert using Google Gemini
result = await convert_model(
    input_model="gemini-pro",
    output_path="./my-slm",
    provider="google",
    compression_factor=0.5
)

## Configuration

Configure providers via environment variables:
- `OPENAI_API_KEY`: Your OpenAI API key
- `ANTHROPIC_API_KEY`: Your Anthropic API key
- `GOOGLE_API_KEY`: Your Google API key
- `LIQUID_API_KEY`: Your LiquidAI API key

Or use the CLI config commands:
```bash
llm2slm config --set OPENAI_API_KEY your-openai-key-here
llm2slm config --set ANTHROPIC_API_KEY your-anthropic-key-here
llm2slm config --set GOOGLE_API_KEY your-google-key-here
llm2slm config --set LIQUID_API_KEY your-liquid-key-here

Development

Setup

pip install -r requirements-dev.txt
pre-commit install

Testing

pytest --cov=llm2slm

Building

python -m build

Project Structure

src/llm2slm/
├── __init__.py          # Package initialization and version info
├── cli.py               # Command-line interface
├── core/                # Core functionality
│   ├── __init__.py
│   ├── config.py        # Configuration management
│   └── pipeline.py      # Conversion pipeline
├── providers/           # LLM provider integrations
│   ├── __init__.py
│   ├── base.py          # Base provider interface
│   └── openai.py        # OpenAI provider implementation
├── server/              # FastAPI server
│   ├── __init__.py
│   └── app.py           # FastAPI application
└── slm/                 # Small Language Model components
    ├── __init__.py
    ├── benchmark.py     # Performance benchmarking
    ├── export.py        # Model export functionality
    ├── loaders.py       # Model loading with factory pattern
    ├── metadata.py      # Metadata creation
    ├── model.py         # SLM model representation
    └── runtime.py       # SLM runtime management

Contact & Support

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository.
  2. Create a feature branch.
  3. Add tests and ensure coverage.
  4. Submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for version history.

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

llm2slm-0.1.0.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

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

llm2slm-0.1.0-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file llm2slm-0.1.0.tar.gz.

File metadata

  • Download URL: llm2slm-0.1.0.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for llm2slm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 895c3d711bd22c728fff86baa8c13ace6d1f446b10dba8f8e23de4215ab3f0d2
MD5 c7dcea96849df70cb3d3dd51caa7f5b8
BLAKE2b-256 3829aaa7987657eec07d0800f3a448ceaeabefcbfbd2f863191de2201f937bb3

See more details on using hashes here.

File details

Details for the file llm2slm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm2slm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for llm2slm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 197335917df8cba9d166c7db09a63895c3b1aadd774cc0fa6fa62e7b9144ab3e
MD5 f1152b90a7268dcf084971e1df429035
BLAKE2b-256 6f2c66e6e050ddd6dfb61d99d9d0c1c5aeda4a8d804fd3862c343fd03bcadffd

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