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.

IModelSessionService.cs 4.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using LLama.Web.Common;
  2. using LLama.Web.Models;
  3. namespace LLama.Web.Services
  4. {
  5. public interface IModelSessionService
  6. {
  7. /// <summary>
  8. /// Gets the ModelSession with the specified Id.
  9. /// </summary>
  10. /// <param name="sessionId">The session identifier.</param>
  11. /// <returns>The ModelSession if exists, otherwise null</returns>
  12. Task<ModelSession> GetAsync(string sessionId);
  13. /// <summary>
  14. /// Gets all ModelSessions
  15. /// </summary>
  16. /// <returns>A collection oa all Model instances</returns>
  17. Task<IEnumerable<ModelSession>> GetAllAsync();
  18. /// <summary>
  19. /// Creates a new ModelSession
  20. /// </summary>
  21. /// <param name="sessionId">The session identifier.</param>
  22. /// <param name="sessionConfig">The session configuration.</param>
  23. /// <param name="inferenceOptions">The default inference configuration, will be used for all inference where no infer configuration is supplied.</param>
  24. /// <param name="cancellationToken">The cancellation token.</param>
  25. /// <returns></returns>
  26. /// <exception cref="System.Exception">
  27. /// Session with id {sessionId} already exists
  28. /// or
  29. /// Failed to create model session
  30. /// </exception>
  31. Task<ModelSession> CreateAsync(string sessionId, ISessionConfig sessionConfig, InferenceOptions inferenceOptions = null, CancellationToken cancellationToken = default);
  32. /// <summary>
  33. /// Closes the session
  34. /// </summary>
  35. /// <param name="sessionId">The session identifier.</param>
  36. /// <returns></returns>
  37. Task<bool> CloseAsync(string sessionId);
  38. /// <summary>
  39. /// Runs inference on the current ModelSession
  40. /// </summary>
  41. /// <param name="sessionId">The session identifier.</param>
  42. /// <param name="prompt">The prompt.</param>
  43. /// <param name="inferenceConfig">The inference configuration, if null session default is used</param>
  44. /// <param name="cancellationToken">The cancellation token.</param>
  45. /// <exception cref="System.Exception">Inference is already running for this session</exception>
  46. IAsyncEnumerable<TokenModel> InferAsync(string sessionId, string prompt, InferenceOptions inferenceConfig = null, CancellationToken cancellationToken = default);
  47. /// <summary>
  48. /// Runs inference on the current ModelSession
  49. /// </summary>
  50. /// <param name="sessionId">The session identifier.</param>
  51. /// <param name="prompt">The prompt.</param>
  52. /// <param name="inferenceOptions">The inference configuration, if null session default is used</param>
  53. /// <param name="cancellationToken">The cancellation token.</param>
  54. /// <returns>Streaming async result of <see cref="System.String" /></returns>
  55. /// <exception cref="System.Exception">Inference is already running for this session</exception>
  56. IAsyncEnumerable<string> InferTextAsync(string sessionId, string prompt, InferenceOptions inferenceOptions = null, CancellationToken cancellationToken = default);
  57. /// <summary>
  58. /// Queues inference on the current ModelSession
  59. /// </summary>
  60. /// <param name="sessionId">The session identifier.</param>
  61. /// <param name="prompt">The prompt.</param>
  62. /// <param name="inferenceOptions">The inference configuration, if null session default is used</param>
  63. /// <param name="cancellationToken">The cancellation token.</param>
  64. /// <returns>Completed inference result as string</returns>
  65. /// <exception cref="System.Exception">Inference is already running for this session</exception>
  66. Task<string> InferTextCompleteAsync(string sessionId, string prompt, InferenceOptions inferenceOptions = null, CancellationToken cancellationToken = default);
  67. /// <summary>
  68. /// Cancels the current inference action.
  69. /// </summary>
  70. /// <param name="sessionId">The session identifier.</param>
  71. /// <returns></returns>
  72. Task<bool> CancelAsync(string sessionId);
  73. }
  74. }