namespace LLama.Web.Services { /// /// Service for managing loading/preloading of models at app startup /// /// Type used to identify contexts /// public class ModelLoaderService : IHostedService { private readonly IModelService _modelService; /// /// Initializes a new instance of the class. /// /// The model service. public ModelLoaderService(IModelService modelService) { _modelService = modelService; } /// /// Triggered when the application host is ready to start the service. /// /// Indicates that the start process has been aborted. public async Task StartAsync(CancellationToken cancellationToken) { await _modelService.LoadModels(); } /// /// Triggered when the application host is performing a graceful shutdown. /// /// Indicates that the shutdown process should no longer be graceful. public async Task StopAsync(CancellationToken cancellationToken) { await _modelService.UnloadModels(); } } }