using BotSharp.Abstraction.Functions; using BotSharp.Core.MessageHub; using System.Text.Json.Serialization; namespace BotSharp.Core.Demo.Functions; public class GetWeatherFn : IFunctionCallback { private readonly IServiceProvider _services; public GetWeatherFn(IServiceProvider services) { _services = services; } public string Name => "get_weather"; public string Indication => "Querying weather"; public async Task Execute(RoleDialogModel message) { var args = JsonSerializer.Deserialize(message.FunctionArgs); var conv = _services.GetRequiredService(); var messageHub = _services.GetRequiredService>>(); await Task.Delay(1000); message.Indication = $"Start querying weather data in {args?.City}"; messageHub.Push(new() { EventName = ChatEvent.OnIndicationReceived, Data = message, RefId = conv.ConversationId, ServiceProvider = _services }); await Task.Delay(1500); message.Indication = $"Still working on it, {args?.City}"; messageHub.Push(new() { EventName = ChatEvent.OnIndicationReceived, Data = message, RefId = conv.ConversationId, ServiceProvider = _services }); await Task.Delay(1500); message.Content = $"It is a sunny day!"; message.StopCompletion = false; return true; } } class WeatherLocation { [JsonPropertyName("city")] public string City { get; set; } }