src — models

Module: src-models Cohesion: 0.80 Members: 0

src — models

The src/models module is responsible for the discovery, management, and automatic download of Large Language Models (LLMs) from the HuggingFace Hub. It's designed to facilitate local inference by providing a robust system for handling GGUF-formatted models, including intelligent selection based on available hardware resources.

Purpose and Key Features

The primary goal of this module is to abstract away the complexities of finding, downloading, and managing LLM files. It ensures that the application can easily access the necessary models, optimizing for performance and resource availability.

Key features include:

Core Concepts and Data Structures

The module defines several interfaces and constants that are central to its operation:

The ModelHub Class

The ModelHub class is the central component of this module, extending EventEmitter to provide progress and status updates.

graph TD
    subgraph "src/models"
        ModelHub[ModelHub Class]
        RECOMMENDED_MODELS(RECOMMENDED_MODELS)
        QUANTIZATION_TYPES(QUANTIZATION_TYPES)
    end

    subgraph "External"
        GPUMonitor[src/hardware/gpu-monitor.ts::getGPUMonitor]
        HuggingFace[HuggingFace Hub]
        FileSystem[Node.js fs/path/os]
        Logger[src/utils/logger.js::logger]
    end

    ModelHub -- uses --> RECOMMENDED_MODELS
    ModelHub -- uses --> QUANTIZATION_TYPES
    ModelHub -- calls --> GPUMonitor
    ModelHub -- fetches from --> HuggingFace
    ModelHub -- interacts with --> FileSystem
    ModelHub -- logs via --> Logger

    ModelHub -- emits events --> DownloadProgress(DownloadProgress)
    ModelHub -- emits events --> DownloadedModel(DownloadedModel)

Initialization and Local Model Scanning

Model Discovery and Listing

Intelligent Model Selection

This module integrates with the gpu-monitor to make informed decisions about model and quantization selection.

Model Download Management

The ModelHub handles the entire download process, including resolving file URLs and tracking progress.

Model Deletion

Configuration

Event Emitter

As an EventEmitter, ModelHub emits the following events:

Developers can subscribe to these events to provide UI feedback or react to download lifecycle changes.

Utility Formatting

Singleton Access

The module provides a singleton pattern for ModelHub to ensure a single, consistent instance across the application.

External Integrations

The src/models module relies on several external components:

Contributing and Extending

Developers looking to contribute to this module should be familiar with:

To add new recommended models, update the RECOMMENDED_MODELS constant in model-hub.ts with the appropriate ModelInfo. Ensure the huggingFaceRepo and supportedQuantizations are accurate for the new model.