Skip to main content

A reusable library for managing LLM providers, authentication, and model selection.

Project description

ModelForge

A Python library for managing LLM providers, authentication, and model selection with seamless LangChain integration.

PyPI version Python 3.11+ License: MIT

🚀 Version 1.0.0 - Production Ready!

Installation

Recommended: Virtual Environment

# Create and activate virtual environment
python -m venv model-forge-env
source model-forge-env/bin/activate  # On Windows: model-forge-env\Scripts\activate

# Install package
pip install model-forge-llm

# Verify installation
modelforge --help

Quick Install (System-wide)

pip install model-forge-llm

Quick Start

Option 1: GitHub Copilot via Device Authentication Flow

# Discover GitHub Copilot models
modelforge models list --provider github_copilot

# Set up GitHub Copilot with device authentication
modelforge auth login --provider github_copilot

# Select Claude 3.7 Sonnet via GitHub Copilot
modelforge config use --provider github_copilot --model claude-3.7-sonnet

# Test your setup
modelforge test --prompt "Write a Python function to reverse a string"

Option 2: OpenAI (API Key Required)

# Add OpenAI with your API key
modelforge auth login --provider openai --api-key YOUR_API_KEY

# Select GPT-4o-mini
modelforge config use --provider openai --model gpt-4o-mini

# Test your setup
modelforge test --prompt "Hello, world!"

Option 3: Local Ollama (No API Key Needed)

# Make sure Ollama is running locally
# Then add a local model
modelforge config add --provider ollama --model qwen3:1.7b

# Select the local model
modelforge config use --provider ollama --model qwen3:1.7b

# Test your setup
modelforge test --prompt "What is machine learning?"

Common Commands - Complete Lifecycle

# Installation & Setup
modelforge --help                                   # Verify installation
modelforge config show                             # View current config

# Model Discovery & Selection
modelforge models list                             # List all available models
modelforge models search "claude"                   # Search models by name
modelforge models info --provider openai --model gpt-4o  # Get model details

# Authentication Management
modelforge auth login --provider openai --api-key KEY   # API key auth
modelforge auth login --provider github_copilot         # Device flow auth
modelforge auth status                                 # Check auth status
modelforge auth logout --provider openai               # Remove credentials

# Configuration Management
modelforge config add --provider openai --model gpt-4o-mini --api-key KEY
modelforge config add --provider ollama --model qwen3:1.7b --local
modelforge config use --provider openai --model gpt-4o-mini
modelforge config remove --provider openai --model gpt-4o-mini

# Testing & Usage
modelforge test --prompt "Hello, how are you?"        # Test current model
modelforge test --prompt "Explain quantum computing" --verbose  # Debug mode

# Cache & Maintenance
modelforge models list --refresh                     # Force refresh from models.dev

Python API

Basic Usage

from modelforge.registry import ModelForgeRegistry

# Initialize registry
registry = ModelForgeRegistry()

# Get currently configured model
llm = registry.get_llm()

# Use directly with LangChain
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages([("human", "{input}")])
chain = prompt | llm
response = chain.invoke({"input": "Tell me a joke"})
print(response)

Advanced Usage

from modelforge.registry import ModelForgeRegistry

# Initialize with debug logging
registry = ModelForgeRegistry(verbose=True)

# Get specific model by provider and name
llm = registry.get_llm(provider_name="openai", model_alias="gpt-4o-mini")

# Use with full LangChain features
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

# Create complex chains
prompt = ChatPromptTemplate.from_template("Explain {topic} in simple terms")
chain = prompt | llm | StrOutputParser()

# Use with streaming
for chunk in chain.stream({"topic": "quantum computing"}):
    print(chunk, end="", flush=True)

# Batch processing
questions = [
    "What is machine learning?",
    "Explain neural networks",
    "How does backpropagation work?"
]
responses = chain.batch([{"topic": q} for q in questions])

Configuration Management

from modelforge import config

# Get current model selection
current = config.get_current_model()
print(f"Current: {current.get('provider')}/{current.get('model')}")

# Check if models are configured
if not current:
    print("No model selected. Configure with:")
    print("modelforge config add --provider openai --model gpt-4o-mini")

Error Handling

from modelforge.registry import ModelForgeRegistry
from modelforge.exceptions import ConfigurationError, ProviderError

try:
    registry = ModelForgeRegistry()
    llm = registry.get_llm()
    response = llm.invoke("Hello world")
except ConfigurationError as e:
    print(f"Configuration issue: {e}")
    print("Run: modelforge config add --provider PROVIDER --model MODEL")
except ProviderError as e:
    print(f"Provider error: {e}")
    print("Check: modelforge auth status")

Supported Providers

  • OpenAI: GPT-4, GPT-4o, GPT-3.5-turbo
  • Google: Gemini Pro, Gemini Flash
  • Ollama: Local models (Llama, Qwen, Mistral)
  • GitHub Copilot: Claude, GPT models via GitHub

Authentication

ModelForge supports multiple authentication methods:

  • API Keys: Store securely in configuration
  • Device Flow: Browser-based OAuth for GitHub Copilot
  • No Auth: For local models like Ollama
# API Key authentication
modelforge auth login --provider openai --api-key YOUR_KEY

# Device flow (GitHub Copilot)
modelforge auth login --provider github_copilot

# Check auth status
modelforge auth status

Configuration

ModelForge uses a two-tier configuration system:

  • Global: ~/.config/model-forge/config.json (user-wide)
  • Local: ./.model-forge/config.json (project-specific)

Local config takes precedence over global when both exist.

Model Discovery

# List all available models
modelforge models list

# Search models by name or capability
modelforge models search "gpt"

# Get detailed model info
modelforge models info --provider openai --model gpt-4o

Development Setup

For contributors and developers:

git clone https://github.com/smiao-icims/model-forge.git
cd model-forge

# Quick setup with uv (recommended)
./setup.sh

# Or manual setup
uv sync --extra dev
uv run pytest

Requirements:

  • Python 3.11+
  • uv (modern Python package manager)

See CONTRIBUTING.md for detailed development guidelines.

Documentation

License

MIT License - see LICENSE file for details.

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

model_forge_llm-1.0.0.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

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

model_forge_llm-1.0.0-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file model_forge_llm-1.0.0.tar.gz.

File metadata

  • Download URL: model_forge_llm-1.0.0.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for model_forge_llm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f9528908a6a275fba8ff4495637ab0ef2f08a1cf5a28529cfcb50a0dd73a206c
MD5 bd3f8f317437f70ad2ea83fef97a82c2
BLAKE2b-256 767971b803eabab3f6316c777af52f3ef11cd7a7c370a1a30cf536d5c7589954

See more details on using hashes here.

File details

Details for the file model_forge_llm-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for model_forge_llm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0291cdc4419c431eca8dc99b2edfdc059d7264570dba882e689d6bffcc7acd7
MD5 0a089afb2b46f91e2b1ccf295f7efad5
BLAKE2b-256 2d569fb43e24e955b9c32da38e5023a6c7fe6834cc00fec15318cdc7372d072b

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