-
Notifications
You must be signed in to change notification settings - Fork 181
epic: SQLite database implementation #1241
Description
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
- Thread-safe Operations: Uses mutex locking to ensure thread safety for all operations.
- File-based Storage: Manages model information in a text file, allowing for persistence between program runs.
- Unique Identifier Generation: Automatically generates unique, shortened aliases for models.
- CRUD Operations: Supports Creating, Reading, Updating, and Deleting model entries.
- 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 modelauthor_repo_id: Author or repository identifierbranch_name: Branch name in the repositorypath_to_model_yaml: Path to the model's YAML filemodel_alias: Shortened alias for the modelstatus: Current status of the model (READY or RUNNING)
ModelListUtils Class Methods
-
LoadModelList()
- Loads model entries from the file, creating the file if it doesn't exist.
- Returns a vector of ModelEntry objects.
-
SaveModelList()
- Saves the current list of model entries to the file.
-
GetModelInfo(identifier)
- Retrieves model information based on model_id or model_alias.
- Throws an exception if the model is not found.
-
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.
-
UpdateModelEntry(identifier, updated_entry)
- Updates an existing model entry.
- Identified by either model_id or model_alias.
-
DeleteModelEntry(identifier)
- Deletes a model entry if it exists and is in READY state.
-
PrintModelInfo(entry)
- Prints detailed information about a model entry.
-
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:
- Filename only (e.g.,
model_id_xxx) - Parent directory + filename (e.g.,
llama3.1-7b-gguf:model_id_xxx) - Grandparent directory + parent directory + filename (e.g.,
bartowski:llama3.1-7b-gguf/model_id_xxx) - 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.