SmartChatBoxAdapter
Namespace: Wisej.AI.Adapters
Assembly: Wisej.AI
Turns the ChatBox control into a AI-powered bot. It can answer any question (depending on the AI model being used) and can invoke methods in your applications as needed (see SmartTool).
- C#
- VB.NET
public class SmartChatBoxAdapter : SmartAdapter
Public Class SmartChatBoxAdapter
Inherits SmartAdapter
Works with:
- AzureAI/OpenAI gpt-4
- AzureAI/OpenAI gpt-4o
- AzureAI/OpenAI gpt-3.5
- AzureAI/Anthropic Claude
- Google Gemini
- Llama3:8b and 70b
You are not limited to what the model can answer. When you add a method decorated with the ToolAttribute the AI can invoke it when necessary in order to retrieve any information or take any action. This is a simple example that provides current date/time knowledge to the AI bot, including the name of the day:
[SmartTool.Tool]
[Description("Returns the current date and time.")]
public DateTime GetCurrentDateTime() {
return DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
}
When the AI needs to know the current date/time it will invoke this method. For example: "When is the next national holiday in {country}?". In this example you can see how to allow the AI to take an action.
[SmartTool.Tool]
[Description("Changes the background color of the application header.")]
public void SetHeaderColor(
[Description("Name of the new color. Use @toolbar to reset to the original color.")]
string color)
{
((MainPage)Application.MainPage).panelHeader.BackColor = Color.FromName(color);
}
When the AI wants to change the header color it will invoke this method with the correct parameter. Use this feature with a lot of caution! A method like "LaunchThermonuclearStrike()" is not allowed.
Constructors
SmartChatBoxAdapter()
Initializes a new instance of SmartChatBoxAdapter.
Properties
AutoReset
Boolean: Gets or sets a value indicating whether the history of the conversation is cleared after each response. (Default: False)
BotAvatar
String: Icon of the AI bot. (Default: "resource.wx/Wisej.AI/Icons/wisej-avatar.svg")
BotName
String: Name of the AI bot. (Default: "Wisej.AI")
ChatBox
User
User: The User associated to the AI bot. It's created using BotName and BotAvatar.
Methods
FormatAnswer(answer, sources)
| Parameter | Type | Description |
|---|---|---|
| answer | String | |
| sources | String[] |
Returns: String.
OnAnswerReceived(args)
| Parameter | Type | Description |
|---|---|---|
| args | AnswerReceivedEventArgs |
OnControlCreated(control)
| Parameter | Type | Description |
|---|---|---|
| control | Control |
OnControlDisposed(control)
| Parameter | Type | Description |
|---|---|---|
| control | Control |
OnSourceClicked(args)
| Parameter | Type | Description |
|---|---|---|
| args | SourceClickedEventArgs |
ParseAnswer(text)
| Parameter | Type | Description |
|---|---|---|
| text | String |
Returns: String.
ParseSources(text)
| Parameter | Type | Description |
|---|---|---|
| text | String |
Returns: String[].
ResetSession(removeMessages)
Resets the conversation history.
| Parameter | Type | Description |
|---|---|---|
| removeMessages | Boolean | Indicates whether all messages from the ChatBox control should also be removed. |
RunAsyncCore(control)
| Parameter | Type | Description |
|---|---|---|
| control | Control |
Returns: Task<Message>.
Events
AnswerReceived
SourceClicked
Implements
| Name | Description |
|---|---|
| IToolProvider | Represents a provider that supplies tools. |