Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

epic: SQLite database implementation #1241

@nguyenhoangthuan99

Description

@nguyenhoangthuan99

Implement a ModelListUtils class base on this discussion #1154

Overview

The ModelListUtils class provides a robust and thread-safe interface for managing a list of machine learning models. It handles operations such as adding, updating, deleting, and retrieving model information, with a focus on maintaining unique identifiers for each model.

Key Features

  1. Thread-safe Operations: Uses mutex locking to ensure thread safety for all operations.
  2. File-based Storage: Manages model information in a text file, allowing for persistence between program runs.
  3. Unique Identifier Generation: Automatically generates unique, shortened aliases for models.
  4. CRUD Operations: Supports Creating, Reading, Updating, and Deleting model entries.
  5. Error Handling: Robust error checking and exception throwing for invalid operations.

Main Components

ModelEntry Struct

Represents a single model entry with fields:

  • model_id: Unique identifier for the model
  • author_repo_id: Author or repository identifier
  • branch_name: Branch name in the repository
  • path_to_model_yaml: Path to the model's YAML file
  • model_alias: Shortened alias for the model
  • status: Current status of the model (READY or RUNNING)

ModelListUtils Class Methods

  1. LoadModelList()

    • Loads model entries from the file, creating the file if it doesn't exist.
    • Returns a vector of ModelEntry objects.
  2. SaveModelList()

    • Saves the current list of model entries to the file.
  3. GetModelInfo(identifier)

    • Retrieves model information based on model_id or model_alias.
    • Throws an exception if the model is not found.
  4. AddModelEntry(new_entry, use_short_alias)

    • Adds a new model entry to the list.
    • Optionally generates a shortened alias for the model.
    • Ensures uniqueness of model_id and model_alias.
  5. UpdateModelEntry(identifier, updated_entry)

    • Updates an existing model entry.
    • Identified by either model_id or model_alias.
  6. DeleteModelEntry(identifier)

    • Deletes a model entry if it exists and is in READY state.
  7. PrintModelInfo(entry)

    • Prints detailed information about a model entry.
  8. GenerateShortenedAlias(model_id, entries)

    • Generates a unique, shortened alias for a model.
    • Uses a hierarchical approach to create aliases, prioritizing brevity while ensuring uniqueness.

Alias Generation Logic

The GenerateShortenedAlias function creates aliases in the following order:

  1. Filename only (e.g., model_id_xxx)
  2. Parent directory + filename (e.g., llama3.1-7b-gguf:model_id_xxx)
  3. Grandparent directory + parent directory + filename (e.g., bartowski:llama3.1-7b-gguf/model_id_xxx)
  4. Full path (e.g., huggingface.co:bartowski/llama3.1-7b-gguf/model_id_xxx)

It returns the shortest unique alias, appending a numeric suffix if necessary to ensure uniqueness.

Metadata

Metadata

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions