Skip to main content

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).

public class SmartChatBoxAdapter : 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

ChatBox:

User

User: The User associated to the AI bot. It's created using BotName and BotAvatar.

Methods

FormatAnswer(answer, sources)

ParameterTypeDescription
answerString
sourcesString[]

Returns: String.

OnAnswerReceived(args)

ParameterTypeDescription
argsAnswerReceivedEventArgs

OnControlCreated(control)

ParameterTypeDescription
controlControl

OnControlDisposed(control)

ParameterTypeDescription
controlControl

OnSourceClicked(args)

ParameterTypeDescription
argsSourceClickedEventArgs

ParseAnswer(text)

ParameterTypeDescription
textString

Returns: String.

ParseSources(text)

ParameterTypeDescription
textString

Returns: String[].

ResetSession(removeMessages)

Resets the conversation history.

ParameterTypeDescription
removeMessagesBooleanIndicates whether all messages from the ChatBox control should also be removed.

RunAsyncCore(control)

ParameterTypeDescription
controlControl

Returns: Task<Message>.

Events

AnswerReceived

AnswerReceivedEventHandler

SourceClicked

SourceClickedEventHandler

Implements

NameDescription
IToolProviderRepresents a provider that supplies tools.