Class ModelCard
Represents metadata and attributes for a language model in the LM-Kit library.
public class ModelCard
- Inheritance
-
ModelCard
- Inherited Members
Examples
Example: List all predefined models
using LMKit.Model;
using System;
// Get all predefined model cards
var modelCards = ModelCard.GetPredefinedModelCards();
Console.WriteLine($"Available models: {modelCards.Count}");
foreach (var card in modelCards)
{
Console.WriteLine($"- {card.ModelID}: {card.ModelName}");
Console.WriteLine($" Capabilities: {card.Capabilities}");
Console.WriteLine($" Parameters: {card.ParameterCount:N0}");
Console.WriteLine();
}
Example: Find and load a specific model
using LMKit.Model;
using System;
// Find a model by ID
ModelCard card = ModelCard.GetPredefinedModelCardByModelID("llama-3.2-1b");
if (card != null)
{
Console.WriteLine($"Found: {card.ModelName}");
Console.WriteLine($"License: {card.License}");
Console.WriteLine($"Context length: {card.ContextLength}");
Console.WriteLine($"File size: {card.FileSize:N0} bytes");
// Load the model
LM model = new LM(card);
Console.WriteLine($"Model loaded: {model.Name}");
}
Example: Filter models by capability
using LMKit.Model;
using System;
using System.Linq;
// Get all embedding models
var embeddingModels = ModelCard.GetPredefinedModelCards()
.Where(c => c.Capabilities.HasFlag(ModelCapabilities.TextEmbeddings))
.ToList();
Console.WriteLine($"Embedding models: {embeddingModels.Count}");
foreach (var card in embeddingModels)
{
Console.WriteLine($"- {card.ModelID} (dim: {card.ContextLength})");
}
// Get all vision-capable models
var visionModels = ModelCard.GetPredefinedModelCards()
.Where(c => c.Capabilities.HasFlag(ModelCapabilities.Vision))
.ToList();
Console.WriteLine($"Vision models: {visionModels.Count}");
Example: Create a custom model card
using LMKit.Model;
using System;
// Create a model card from a local file
ModelCard customCard = ModelCard.CreateFromFile("my-custom-model.gguf");
Console.WriteLine($"Custom model: {customCard.ModelName}");
Console.WriteLine($"Architecture: {customCard.Architecture}");
// Load the custom model
LM model = new LM(customCard);
Remarks
The ModelCard class provides comprehensive metadata about language models, including model capabilities, download URLs, licensing information, and technical specifications. It serves as the primary way to discover and load predefined models in LM-Kit.NET.
Key Features
- Access predefined models via GetPredefinedModelCards(bool)
- Find specific models by ID via GetPredefinedModelCardByModelID(string)
- Create custom model cards for local or custom models
- Detailed model metadata (capabilities, size, architecture, license)
Key Properties
- ModelID - Unique identifier for the model
- ModelName - Human-readable model name
- ModelUri - Download URI for the model file
- Capabilities - Model capabilities (text generation, embeddings, vision, etc.)
- ContextLength - Maximum context window size
- ParameterCount - Number of model parameters
- License - Model license type
Model Categories
Predefined models include text generation models, embedding models, vision models,
speech-to-text models, and reranking models for various use cases.
Constructors
- ModelCard(Uri)
Initializes a new instance of the ModelCard class with the specified model URI.
Properties
- Architecture
Gets or sets the architecture type of the model. Ie: 'llama', 'bert', 'phi3'...
- Capabilities
Gets or sets the capabilities of the model, indicating the tasks it is designed to perform. Examples: Chat, Embeddings, TextGeneration, CodeCompletion.
- ContextLength
Gets or sets the maximum context length (in tokens) supported by the model.
- Description
Gets or sets a brief description of the model, explaining its purpose or capabilities.
- FileName
Gets the name of the file associated with the model's URI. If the URI points to a local file, the file name is extracted from the path. If the URI represents a remote model, the name is derived.
- FileSize
Gets or sets the size of the model file in bytes.
- Format
Gets or sets the format of the model (e.g., GGUF, LMK, ONNX, etc.).
- IsLocallyAvailable
Gets a value indicating whether the model file is locally available.
- IsPredefined
Indicates whether the model is part of the predefined collection of commonly used models.
- License
Gets or sets the license associated with the model. This defines how the model can be used or distributed. Example: "apache-2.0", "mit", or "proprietary".
- LocalPath
Gets the local file system path of the model.
- ModelID
Gets or sets the unique identifier for the model. This identifier is used to uniquely reference a model within the LM-Kit library and should conform to industry naming conventions. For predefined models, this value is automatically set and should not be changed. For user-defined models, it can be manually assigned.
- ModelName
Gets or sets the name of the model.
- ModelUri
Gets or sets the URI where the model can be downloaded or accessed.
- ParameterCount
Gets or sets the number of parameters in the model, represented as an unsigned long.
- Publisher
Gets or sets the publisher of the model. If not set explicitly, this information is derived from the model metadata.
- QuantizationPrecision
Gets or sets the quantization precision of the model, represented in bits (e.g., 4-bit, 8-bit).
- ReplacementModel
Gets the replacement model identifier to use when the current model is considered legacy.
- Repository
Gets or sets the repository associated with the model. If not set explicitly, this information is derived from the model metadata.
- SHA256
Gets or sets the SHA-256 checksum of the model file for verification purposes.
- ShortModelName
Gets a shortened version of the model name, typically with certain details like size or other specific information removed.
Methods
- CreateFromFile(string)
Creates a ModelCard instance by loading metadata from the specified file path.
- Download(ModelDownloadingProgressCallback)
Downloads the model file from its specified URI and saves it locally.
- DownloadAsync(ModelDownloadingProgressCallback)
Asynchronously downloads the model file from its specified URI and saves it locally.
- GetPredefinedModelCardByModelID(string)
Retrieves a predefined ModelCard instance by its unique model identifier.
- GetPredefinedModelCards(bool)
Retrieves a predefined list of commonly used ModelCard instances.
- ValidateFileChecksum()
Validates the integrity of the model file by comparing its SHA-256 checksum with the expected checksum.