You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModelLoaderService.cs 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace LLama.Web.Services
  2. {
  3. /// <summary>
  4. /// Service for managing loading/preloading of models at app startup
  5. /// </summary>
  6. /// <typeparam name="T">Type used to identify contexts</typeparam>
  7. /// <seealso cref="Microsoft.Extensions.Hosting.IHostedService" />
  8. public class ModelLoaderService : IHostedService
  9. {
  10. private readonly IModelService _modelService;
  11. /// <summary>
  12. /// Initializes a new instance of the <see cref="ModelLoaderService"/> class.
  13. /// </summary>
  14. /// <param name="modelService">The model service.</param>
  15. public ModelLoaderService(IModelService modelService)
  16. {
  17. _modelService = modelService;
  18. }
  19. /// <summary>
  20. /// Triggered when the application host is ready to start the service.
  21. /// </summary>
  22. /// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
  23. public async Task StartAsync(CancellationToken cancellationToken)
  24. {
  25. await _modelService.LoadModels();
  26. }
  27. /// <summary>
  28. /// Triggered when the application host is performing a graceful shutdown.
  29. /// </summary>
  30. /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
  31. public async Task StopAsync(CancellationToken cancellationToken)
  32. {
  33. await _modelService.UnloadModels();
  34. }
  35. }
  36. }