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?, string, string, string, string)
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, string endpoint = null, string proxy = null, string apiKey = null, string apiKeyHeader = 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. |
| string | endpoint | Optional endpoint URL to override the configured endpoint. |
| string | proxy | Optional proxy URL to override the configured proxy. |
| string | apiKey | Optional API key to override the configured API key. |
| string | apiKeyHeader | Optional API key header name to override the configured header. |
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. |