BotSharp/src/Infrastructure/BotSharp.Core/Demo/Functions/GetWeatherFn.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2025-05-13 16:45:19 +00:00
using BotSharp.Abstraction.Functions;
2025-07-28 22:41:28 +00:00
using BotSharp.Core.MessageHub;
2025-05-13 16:45:19 +00:00
2025-05-16 03:59:57 +00:00
namespace BotSharp.Core.Demo.Functions;
2025-05-13 16:45:19 +00:00
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<bool> Execute(RoleDialogModel message)
{
2025-07-28 22:41:28 +00:00
var conv = _services.GetRequiredService<IConversationService>();
2025-07-29 18:55:53 +00:00
var messageHub = _services.GetRequiredService<MessageHub<HubObserveData<RoleDialogModel>>>();
2025-07-28 22:41:28 +00:00
await Task.Delay(1000);
message.Indication = "Start querying weather data";
messageHub.Push(new()
{
EventName = ChatEvent.OnIndicationReceived,
Data = message,
ServiceProvider = _services
});
await Task.Delay(1500);
message.Indication = "Still working on it";
messageHub.Push(new()
{
EventName = ChatEvent.OnIndicationReceived,
Data = message,
ServiceProvider = _services
});
await Task.Delay(1500);
2025-05-16 04:02:38 +00:00
message.Content = $"It is a sunny day!";
2025-06-24 02:43:25 +00:00
message.StopCompletion = false;
2025-05-13 16:45:19 +00:00
return true;
}
}