SmartChatBoxAdapter
Overview
SmartChatBoxAdapter
serves as a bridge connecting AI capabilities to the Wisej.Web.Ext.ChatBox control. This integration enables the development of intelligent chatbots that can respond to user inquiries across a wide range of scenarios.
For instance, you can configure it to restrict responses to specific topics. Additionally, you have the option to equip it with tools that enable it to answer questions using data from your SQL database or a collection of documents, among other sources.
In its simplest form, the following single line of code creates a smart chatbot, leveraging the full capabilities of the selected model:
This line establishes a connection between your chat box and the AI model by assigning the SmartChatBoxAdapter
to the adapter of the AI instance associated with chatBox1
.
The SmartChatBoxAdapter is initialized with the following default prompt, which you can override as needed:
As noted in the prompt, the SmartChatBoxAdapter
has the ability to identify and list the sources it utilized to generate its responses. These sources are made available for further processing, allowing for additional analysis or actions based on them. For more details on handling sources, please refer to the Events section below.
You can enhance the capabilities of the SmartChatBoxAdapter by equipping it with various tools that empower it to perform a wide array of tasks. These tools can allow the AI to take specific actions, conduct web searches, access documents, query databases, or interact with any other data sources, both internal and external.
Additionally, you can limit the capabilities of the SmartChatBoxAdapter as needed. This can be achieved through several methods, but the simplest approach is to utilize the SystemPrompt
property. This property allows you to define constraints or guidelines that the AI must adhere to, thereby tailoring its behavior to fit specific requirements or contexts.
Configuration
Properties
In addition to the properties inherited from the SmartAdapter, the SmartChatBoxAdapter exposes the following additional properties.
AutoReset
Determines whether the conversation history is cleared after each response. Preserves the messages in the connected ChatBox.
Default is false.
User
Represents the AI user in the ChatBox as an instance of the ChatBox.User class. This property is read-only and identifies the AI participant within the chat interface. To customize the AI’s display name or avatar, use the BotName and BotAvatar properties, respectively. The property itself cannot be reassigned, but you can modify the AI user's appearance through these options.
BotName
The BotName property specifies the display name of the AI bot within the ChatBox. By default, this name is set to "Wisej." You can use this property to assign a custom name to your bot, allowing you to better personalize the chat experience for your application’s users.
BotAvatar
The BotAvatar property specifies the image that represents the AI bot in the ChatBox. You can set this property to either the name of a built-in image or the URL of a custom image. This allows you to personalize the bot's appearance by displaying a specific avatar in the chat interface.
ChatBox
The ChatBox property is read-only and returns the instance of the ChatBox control associated with the adapter. This association is established when you call this.smartHub.GetAI(this.chatBox)
and assign the adapter using this.smartHub.GetAI(this.chatBox).Adapter = this.smartChatBoxAdapter
. The property provides access to the specific ChatBox control that is linked to the current AI adapter instance.
Methods
ResetSession
Clears the history in the current session. The adapter will create a new session when it processes the next question.
Events
In addition to the events inherited from the SmartAdapter, the SmartChatBoxAdapter exposes the following additional events.
AnswerReceived
The AnswerReceived
event provides all the information related to the answer generated by the AI. Using this event, you can access the list of sources used to generate the answer or apply custom formatting to the response before it is displayed to the user. This allows you to tailor the presentation and handling of AI-generated answers according to your application's requirements.
e.Sources
String array with all the sources extracted by the AI model.
e.Message
The agent message, includes the full text of the answer and the usage.
e.Answer
The original answer from the AI model.
e.FormattedAnswer
The formatted answer that will be displayed to the user in the ChatBox. You can change this property.
SourceClicked
The SourceClicked
event enables your application to respond when a user clicks on an item in the list of sources. Within the event handler, you can access the e.Source
property to obtain the name of the source that was clicked
Last updated