Interface IAIChatService
Interface for getting chat completions from an AI model with conversation memory.
Namespace: Radzen
Assembly: Radzen.Blazor.dll
Syntax
public interface IAIChatService
Methods
CleanupOldSessions(int)
Removes old conversation sessions based on age.
Declaration
void CleanupOldSessions(int maxAgeHours = 24)
Parameters
Type | Name | Description |
---|---|---|
int | maxAgeHours | Maximum age in hours for sessions to keep. |
ClearSession(string)
Clears the conversation history for a specific session.
Declaration
void ClearSession(string sessionId)
Parameters
Type | Name | Description |
---|---|---|
string | sessionId | The session ID to clear. |
GetActiveSessions()
Gets all active conversation sessions.
Declaration
IEnumerable<ConversationSession> GetActiveSessions()
Returns
Type | Description |
---|---|
IEnumerable<ConversationSession> | A list of active conversation sessions. |
GetCompletionsAsync(string, string, CancellationToken, string, string, double?, int?)
Streams chat completion responses from the AI model asynchronously with conversation memory.
Declaration
IAsyncEnumerable<string> GetCompletionsAsync(string userInput, string sessionId = null, CancellationToken cancellationToken = default, string model = null, string systemPrompt = null, double? temperature = null, int? maxTokens = null)
Parameters
Type | Name | Description |
---|---|---|
string | userInput | The user's input message to send to the AI model. |
string | sessionId | Optional session ID to maintain conversation context. If null, a new session will be created. |
CancellationToken | cancellationToken | A cancellation token that can be used to cancel the operation. |
string | model | Optional model name to override the configured model. |
string | systemPrompt | Optional system prompt to override the configured system prompt. |
double? | temperature | Optional temperature to override the configured temperature. |
int? | maxTokens | Optional maximum tokens to override the configured max tokens. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<string> | An async enumerable that yields streaming response chunks from the AI model. |
GetOrCreateSession(string)
Gets or creates a conversation session.
Declaration
ConversationSession GetOrCreateSession(string sessionId = null)
Parameters
Type | Name | Description |
---|---|---|
string | sessionId | The session ID. If null, a new session will be created. |
Returns
Type | Description |
---|---|
ConversationSession | The conversation session. |