UtilityTools
Overview
UtilityTools
provide a simple set of general helper functions, such as get_current_date_time
and get_user_location
.
This is the prompt:
#
# UtilityTools
#
[UtilityTools]
Provides generally useful tools.
[UtilityTools.get_current_date_time]
Returns the current date and time
[UtilityTools.get_user_location]
Returns the user current location
The get_user_location
tool is particularly interesting because it utilizes the geolocation extension from Wisej.NET, enabling the browser to access the PC's location services. The implementation looks like this:
[SmartTool.Tool]
[Description("[UtilityTools.get_user_location]")]
protected virtual async Task<string> get_user_location()
{
_geolocation = _geolocation ?? new Geolocation();
var tcs = new TaskCompletionSource<string>();
_geolocation.GetCurrentPosition((position) =>
{
tcs.SetResult(position.ToString());
});
Application.Update(Application.Current);
return await tcs.Task;
}
Notice that it employs the TaskCompletionSource
technique to convert a callback into a Task
. This is necessary because the browser's location services support only callbacks.
Using UtilityTools
To enable the use of UtilityTools, simply add it to a SmartHub, SmartAdapter, or SmartPrompt.
this.hub1.UseTools(new UtilityTools());
this.smartDataEntryAdapter1.UseTools(new UtilityTools());
Console.WriteLine(
new SmartPrompt()
.UseTools(new UtilityTools())
.AskAsync(endpoint, "Where am I?")
.Result.Text);
Last updated