2023-10-04 07:57:15 +08:00
using LLama.Web.Common ;
2023-07-19 04:55:56 +08:00
using LLama.Web.Models ;
2023-07-16 17:39:11 +08:00
namespace LLama.Web.Services
2023-07-16 15:31:27 +08:00
{
public interface IModelSessionService
{
2023-10-04 07:57:15 +08:00
/// <summary>
/// Gets the ModelSession with the specified Id.
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <returns>The ModelSession if exists, otherwise null</returns>
2023-07-23 12:31:28 +08:00
Task < ModelSession > GetAsync ( string sessionId ) ;
2023-07-16 15:31:27 +08:00
2023-10-04 07:57:15 +08:00
/// <summary>
/// Gets all ModelSessions
/// </summary>
/// <returns>A collection oa all Model instances</returns>
Task < IEnumerable < ModelSession > > GetAllAsync ( ) ;
/// <summary>
/// Creates a new ModelSession
/// </summary>
/// <param name="sessionId">The session identifier.</param>
2023-10-04 08:35:18 +08:00
/// <param name="sessionConfig">The session configuration.</param>
2023-10-04 07:57:15 +08:00
/// <param name="inferenceOptions">The default inference configuration, will be used for all inference where no infer configuration is supplied.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <exception cref="System.Exception">
/// Session with id {sessionId} already exists
/// or
/// Failed to create model session
/// </exception>
2023-10-04 08:35:18 +08:00
Task < ModelSession > CreateAsync ( string sessionId , ISessionConfig sessionConfig , InferenceOptions inferenceOptions = null , CancellationToken cancellationToken = default ) ;
2023-10-04 07:57:15 +08:00
/// <summary>
/// Closes the session
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <returns></returns>
Task < bool > CloseAsync ( string sessionId ) ;
/// <summary>
/// Runs inference on the current ModelSession
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <param name="prompt">The prompt.</param>
/// <param name="inferenceConfig">The inference configuration, if null session default is used</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.Exception">Inference is already running for this session</exception>
IAsyncEnumerable < TokenModel > InferAsync ( string sessionId , string prompt , InferenceOptions inferenceConfig = null , CancellationToken cancellationToken = default ) ;
/// <summary>
/// Runs inference on the current ModelSession
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <param name="prompt">The prompt.</param>
/// <param name="inferenceOptions">The inference configuration, if null session default is used</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Streaming async result of <see cref="System.String" /></returns>
/// <exception cref="System.Exception">Inference is already running for this session</exception>
IAsyncEnumerable < string > InferTextAsync ( string sessionId , string prompt , InferenceOptions inferenceOptions = null , CancellationToken cancellationToken = default ) ;
/// <summary>
/// Queues inference on the current ModelSession
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <param name="prompt">The prompt.</param>
/// <param name="inferenceOptions">The inference configuration, if null session default is used</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Completed inference result as string</returns>
/// <exception cref="System.Exception">Inference is already running for this session</exception>
Task < string > InferTextCompleteAsync ( string sessionId , string prompt , InferenceOptions inferenceOptions = null , CancellationToken cancellationToken = default ) ;
/// <summary>
/// Cancels the current inference action.
/// </summary>
/// <param name="sessionId">The session identifier.</param>
/// <returns></returns>
Task < bool > CancelAsync ( string sessionId ) ;
}
2023-07-16 15:31:27 +08:00
}