SmartSession
Wisej.AI.SmartSession
Namespace: Wisej.AI
Assembly: Wisej.AI (3.5.0.0)
Represents a session that manages interactions with a smart hub and endpoint, handling prompts, messages, and tools within the session context.
public class SmartSession : SmartObject
The SmartSession class is responsible for managing the lifecycle of a session, including initialization, message handling, and tool usage. It supports asynchronous operations for asking questions and processing responses, and it can handle context overflow through truncation or summarization strategies.
Constructors
SmartSession(hub, systemPrompt)

Initializes a new instance of the SmartSession class with the specified hub and optional system prompt.
Throws:
ArgumentNullException Thrown when the hub is null.
SmartSession(endpoint, systemPrompt)

Initializes a new instance of the SmartSession class with the specified endpoint and optional system prompt.
Throws:
ArgumentNullException Thrown when the endpoint is null.
Properties
Endpoint

SmartEndpoint: Gets the smart endpoint associated with the session.
HasModelOptions

Boolean: Gets a value indicating whether the session has model options.
Hub

SmartHub: Gets the smart hub associated with the session.
IsDisposed

Boolean: Gets a value indicating whether the session has been disposed.
Messages

MessageCollection: Gets the collection of messages in the session.
ModelOptions

Object: Gets or sets the model options for the session.
Response

Message: Gets the last response message from the assistant.
SystemPrompt

SmartPrompt: Gets the system prompt for the session.
Methods
AskAsync(question, image)

Asynchronously asks a question and returns the response message.
Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result.
Throws:
ObjectDisposedException Thrown when the session is disposed.
ArgumentNullException Thrown when the question is null.
AskAsync(message)

Asynchronously asks a question using a message and returns the response message.
Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result.
Throws:
ObjectDisposedException Thrown when the session is disposed.
ArgumentNullException Thrown when the message is null.
AskAsyncCore(question)

Asynchronously sends a question to the AI and processes the response.
Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result containing the AI's response.
This method handles the communication with the AI, including managing the session's message context, handling tool calls, and processing AI responses. It ensures that the session is not disposed and that the question is not null before proceeding. The method also manages the context window size and handles exceptions such as token limit exceedance.
var response = await AskAsyncCore(new Message { Text = "What is the weather today?" });
Console.WriteLine(response.Text);
ConvertParameter(value)

Raises the ConvertParameter event.
Returns: String.
Dispose()

Releases all resources used by the SmartSession.
GetParameterValue(parameter)

Gets the value of a parameter.
Returns: String. The value of the parameter as a string.
IsTerminated()

Returns: Boolean.
PrepareSessionMessages(messages)

Prepares session messages by replacing parameters in the system and user messages.
RemoveTool(tool)

Removes a tool from the smart session.
Returns: SmartSession. The current SmartSession instance.
Throws:
ArgumentNullException Thrown when the tool is null.
ReplaceParameters(prompt)

Replaces parameters in the given prompt with their values.
Returns: String. The prompt with parameters replaced by their values.
TrimMessagesAsync(messages)

Trims messages in the session based on the specified truncation strategy.
Returns: Task.
UseTool(tool)

Registers a tool using a delegate.
Returns: SmartSession. The current SmartSession instance.
Throws:
ArgumentNullException Thrown when the tool is null.
UseTools(target)

Registers the tools declared on the target.
Returns: SmartSession. The current SmartSession instance.
Inherited By
Last updated