Removes old conversation sessions from the cache of this service instance based on age.
Declaration
public abstract void CleanupOldSessions(int maxAgeHours)
Parameters
Clears the messages of a conversation and saves it.
Declaration
public abstract void ClearSession(string sessionId)
Parameters
Clears the messages of a conversation and saves it.
Declaration
public abstract Task ClearSessionAsync(string sessionId, Threading.CancellationToken cancellationToken)
Parameters
Returns
Deletes a conversation from the store.
Declaration
public abstract Task DeleteSessionAsync(string sessionId, Threading.CancellationToken cancellationToken)
Parameters
Returns
Gets the conversation sessions cached by this service instance. Prefer CancellationToken), which lists the store.
Declaration
public abstract IEnumerable<ConversationSession> GetActiveSessions()
Returns
Gets the IChatClient the service sends requests with: the one registered in the service collection or an OpenAICompatibleChatClient configured from AIChatServiceOptions, wrapped in a FunctionInvokingChatClient. Use it for one-off completions outside of a conversation.
Declaration
public abstract Microsoft.Extensions.AI.IChatClient GetChatClient(string endpoint, string proxy, string apiKey, string apiKeyHeader)
Parameters
Returns
Streams chat completion responses from the AI model asynchronously with conversation memory.
Declaration
public abstract IAsyncEnumerable<string> GetCompletionsAsync(string userInput, string sessionId, Threading.CancellationToken cancellationToken, string model, string systemPrompt, double? temperature, int? maxTokens, string endpoint, string proxy, string apiKey, string apiKeyHeader)
Parameters
Returns
Gets the IEmbeddingGenerator<T1, T2> used for semantic search and similar scenarios: the one registered in the service collection or an OpenAICompatibleEmbeddingGenerator configured from AIChatServiceOptions.
Declaration
public abstract Microsoft.Extensions.AI.IEmbeddingGenerator<string, Microsoft.Extensions.AI.Embedding<float>> GetEmbeddingGenerator()
Returns
Gets a conversation session from the store, or creates it. The session is cached for the lifetime of the service and saved to the store after every response.
Declaration
public abstract ConversationSession GetOrCreateSession(string sessionId)
Parameters
Returns
Gets a conversation session from the store, or creates it. The session is cached for the lifetime of the service and saved to the store after every response.
Declaration
public abstract Task<ConversationSession> GetOrCreateSessionAsync(string sessionId, string userId, Threading.CancellationToken cancellationToken)
Parameters
Returns
Lists the conversations in the store, most recently updated first.
Declaration
public abstract Task<IReadOnlyList<ConversationSession>> GetSessionsAsync(string userId, Threading.CancellationToken cancellationToken)
Parameters
Returns
Streams the response of the AI model to a message with conversation memory. Tools in Tools are invoked automatically; their calls and results are yielded as FunctionCallContent and FunctionResultContent and a tool wrapped in ApprovalRequiredAIFunction yields a ToolApprovalRequestContent that must be answered with a message carrying a ToolApprovalResponseContent.
Declaration
public abstract IAsyncEnumerable<Microsoft.Extensions.AI.ChatResponseUpdate> GetStreamingResponseAsync(Microsoft.Extensions.AI.ChatMessage message, string sessionId, Microsoft.Extensions.AI.ChatOptions options, string endpoint, string proxy, string apiKey, string apiKeyHeader, string userId, Threading.CancellationToken cancellationToken)
Parameters
Returns
Offers the service a message the user sent while a response of the session is still streaming, when QueueMessages is true. Return true to take the message: the service gives it to the model as part of the running response, for example once the tool calls in progress finish, and the chat shows it as sent. The default returns false: the chat keeps the message and sends it with CancellationToken) once the response completes. AIChatService forwards to the IChatMessageQueue its chat client exposes through Object).
Declaration
public virtual Task<bool> TryQueueMessageAsync(Microsoft.Extensions.AI.ChatMessage message, string sessionId, Threading.CancellationToken cancellationToken)
Parameters
Returns