SmartSession
Wisej.AI.SmartSession
Last updated
Wisej.AI.SmartSession
Last updated
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.
The 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.
Initializes a new instance of the class with the specified hub and optional system prompt.
hub
The smart hub associated with the session.
systemPrompt
The optional system prompt for the session. Default is null.
Throws:
Thrown when the hub is null.
endpoint
The smart endpoint associated with the session.
systemPrompt
The optional system prompt for the session. Default is null.
Throws:
Asynchronously asks a question and returns the response message.
question
The question to ask.
An optional image associated with the question. Default is null.
Throws:
Asynchronously asks a question using a message and returns the response message.
message
The message containing the question.
Throws:
Asynchronously sends a question to the AI and processes the response.
question
The message containing the question to be sent to the AI.
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.
value
Gets the value of a parameter.
parameter
The parameter to get the value for.
Prepares session messages by replacing parameters in the system and user messages.
messages
The collection of messages to prepare.
Removes a tool from the smart session.
tool
The tool to remove.
Throws:
Replaces parameters in the given prompt with their values.
prompt
The prompt containing parameters to replace.
Trims messages in the session based on the specified truncation strategy.
messages
The collection of messages to trim.
Registers a tool using a delegate.
tool
The delegate representing the tool to register.
Throws:
Registers the tools declared on the target.
target
The target object containing tools to register.
Initializes a new instance of the class with the specified endpoint and optional system prompt.
Thrown when the endpoint is null.
: Gets the smart endpoint associated with the session.
: Gets a value indicating whether the session has model options.
: Gets the smart hub associated with the session.
: Gets a value indicating whether the session has been disposed.
: Gets the collection of messages in the session.
: Gets or sets the model options for the session.
: Gets the last response message from the assistant.
: Gets the system prompt for the session.
image
Returns: . A task representing the asynchronous operation, with a as the result.
Thrown when the session is disposed.
Thrown when the question is null.
Returns: . A task representing the asynchronous operation, with a as the result.
Thrown when the session is disposed.
Thrown when the message is null.
Returns: . A task representing the asynchronous operation, with a as the result containing the AI's response.
Raises the event.
Returns: .
Releases all resources used by the .
Returns: . The value of the parameter as a string.
Returns: .
Returns: . The current instance.
Thrown when the tool is null.
Returns: . The prompt with parameters replaced by their values.
Returns: .
Returns: . The current instance.
Thrown when the tool is null.
Returns: . The current instance.