V10 / 66cebf3528e0
CurrentTimeTool.cs
Lilith/Core/Tools/CurrentTimeTool.cs
Unchanged from the preceding versionCS
using System.Text.Json;
namespace Lilith.Core.Tools;
public sealed class CurrentTimeTool : ILilithTool
{
public string Name => "get_current_time";
public string Description => "Get the current date and time on this computer, including its time zone and UTC time.";
public JsonElement Parameters => JsonSerializer.SerializeToElement(new
{
type = "object", properties = new { }, additionalProperties = false
});
public Task<string> ExecuteAsync(JsonElement arguments, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
if (arguments.ValueKind != JsonValueKind.Object || arguments.EnumerateObject().Any())
throw new ArgumentException("get_current_time expects an empty argument object.");
var now = DateTimeOffset.UtcNow;
return Task.FromResult(JsonSerializer.Serialize(new
{
local_time = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Local).ToString("O"),
utc_time = now.ToString("O"), time_zone = TimeZoneInfo.Local.Id
}));
}
}