From 23baf7008868c9118a50be4e95f8256fafc1a0ed Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 11 Mar 2025 16:48:44 -0400 Subject: [PATCH 1/5] Update to M.E.AI 9.3.0-preview.1.25161.3 --- Directory.Packages.props | 2 +- .../MicrosoftExtensionsAIChatCompletionProvider.cs | 11 +++++------ .../MicrosoftExtensionsAITextCompletionProvider.cs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4683fc9d..aa76cf61 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -54,7 +54,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs index 37d3877c..6ee77772 100644 --- a/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs @@ -27,7 +27,6 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio private readonly IChatClient _client; private readonly ILogger _logger; private readonly IServiceProvider _services; - private List renderedInstructions = []; private string? _model; /// @@ -46,7 +45,7 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio /// public string Provider => "microsoft.extensions.ai"; - public string Model => _model; + public string Model => _model ?? ""; /// public void SetModelName(string model) => _model = model; @@ -56,7 +55,7 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio { // Before chat completion hook var hooks = _services.GetServices().ToArray(); - renderedInstructions = []; + List renderedInstructions = []; await Task.WhenAll(hooks.Select(hook => hook.BeforeGenerating(agent, conversations))); // Configure options @@ -145,13 +144,13 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio var completion = await _client.GetResponseAsync(messages); - RoleDialogModel result = new(AgentRole.Assistant, string.Concat(completion.Message.Contents.OfType())) + RoleDialogModel result = new(AgentRole.Assistant, completion.Text) { CurrentAgentId = agent.Id, - RenderedInstruction = string.Join("\r\n", renderedInstructions) + //RenderedInstruction = renderedInstructions, }; - if (completion.Message.Contents.OfType().FirstOrDefault() is { } fcc) + if (completion.Messages.SelectMany(m => m.Contents).OfType().FirstOrDefault() is { } fcc) { result.Role = AgentRole.Function; result.MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty; diff --git a/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs index ed0e94d9..ef3b35c7 100644 --- a/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs @@ -51,7 +51,7 @@ public sealed class MicrosoftExtensionsAITextCompletionProvider : ITextCompletio _tokenStatistics.StartTimer(); var completion = await _chatClient.GetResponseAsync(text); - var result = string.Concat(completion.Message.Contents.OfType()); + var result = completion.Text; _tokenStatistics.StopTimer(); // After chat completion hook From 9fe9b123f13039b9a15e6f96fc0e8c061bcba20d Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 11 Mar 2025 20:57:49 -0500 Subject: [PATCH 2/5] HandleUserDtmfReceived --- .../BotSharp.Core.Realtime/Services/RealtimeHub.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs b/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs index 68636bd1..e8548c4d 100644 --- a/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs +++ b/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs @@ -233,7 +233,8 @@ public class RealtimeHub : IRealtimeHub } await _completer.InsertConversationItem(message); - await _completer.TriggerModelInference("Reply based on the user input"); + var instruction = await _completer.UpdateSession(_conn); + await _completer.TriggerModelInference($"{instruction}\r\n\r\nReply based on the user input: {message.Content}"); } private async Task HandleUserDisconnected() From 7d4d233f7e5c6248802b1891893dea8e0f419f0c Mon Sep 17 00:00:00 2001 From: Visagan Guruparan <103048@smsassist.com> Date: Tue, 11 Mar 2025 22:01:16 -0500 Subject: [PATCH 3/5] Update timeout for web driver logic to fetch from appSettings --- .../Browsing/Settings/WebBrowsingSettings.cs | 1 + .../BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs | 7 +++++-- .../BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs | 5 +++-- .../UtilFunctions/UtilWebGoToPageFn.cs | 4 ++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs index e1ae9a79..4aebc1b3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs @@ -4,4 +4,5 @@ public class WebBrowsingSettings { public string Driver { get; set; } = "Playwright"; public bool Headless { get; set; } + public float? DefaultTimeOut { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs index e1041ae6..9e93b2a7 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Browsing.Settings; + namespace BotSharp.Plugin.WebDriver.Functions; public class GoToPageFn : IFunctionCallback @@ -25,7 +27,7 @@ public class GoToPageFn : IFunctionCallback var url = webDriverService.ReplaceToken(args.Url); url = url.Replace("https://https://", "https://"); - + var _webDriver = _services.GetRequiredService(); var result = await _browser.GoToPage(new MessageInfo { AgentId = message.CurrentAgentId, @@ -33,7 +35,8 @@ public class GoToPageFn : IFunctionCallback MessageId = message.MessageId }, new PageActionArgs { - Url = url + Url = url, + Timeout = _webDriver.DefaultTimeOut }); message.Content = result.IsSuccess ? $"Page {url} is open." : $"Page {url} open failed. {result.Message}"; diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs index 92935233..beb412b5 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs @@ -26,7 +26,7 @@ public class OpenBrowserFn : IFunctionCallback var webDriverService = _services.GetRequiredService(); var url = webDriverService.ReplaceToken(args.Url); - + var _webDriver = _services.GetRequiredService(); url = url.Replace("https://https://", "https://"); var msgInfo = new MessageInfo { @@ -40,7 +40,8 @@ public class OpenBrowserFn : IFunctionCallback }); result = await _browser.GoToPage(msgInfo, new PageActionArgs { - Url = url + Url = url, + Timeout = _webDriver.DefaultTimeOut }); if (result.IsSuccess) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs index 675e1ec8..f62a6ae9 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs @@ -1,3 +1,5 @@ +using BotSharp.Abstraction.Browsing.Settings; + namespace BotSharp.Plugin.WebDriver.UtilFunctions; public class UtilWebGoToPageFn : IFunctionCallback @@ -21,6 +23,8 @@ public class UtilWebGoToPageFn : IFunctionCallback { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); + var _webDriver = _services.GetRequiredService(); + args.Timeout = _webDriver.DefaultTimeOut; args.WaitForNetworkIdle = false; args.WaitTime = 5; args.OpenNewTab = true; From e570672a365d4fee9273fa3be1267067b0d4c76c Mon Sep 17 00:00:00 2001 From: Visagan Guruparan <103048@smsassist.com> Date: Wed, 12 Mar 2025 08:49:31 -0500 Subject: [PATCH 4/5] Update default timeout to 30sec --- .../Browsing/Settings/WebBrowsingSettings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs index 4aebc1b3..3245a802 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs @@ -4,5 +4,6 @@ public class WebBrowsingSettings { public string Driver { get; set; } = "Playwright"; public bool Headless { get; set; } - public float? DefaultTimeOut { get; set; } + // Default timeout in milliseconds + public float DefaultTimeOut { get; set; } = 30000; } From 47d728b68a9c1ae3de179fa54cef64b91d3c20b3 Mon Sep 17 00:00:00 2001 From: Visagan Guruparan <103048@smsassist.com> Date: Wed, 12 Mar 2025 08:53:38 -0500 Subject: [PATCH 5/5] Update default timeout to lowercasing --- .../Browsing/Settings/WebBrowsingSettings.cs | 2 +- src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs | 2 +- .../BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs | 2 +- .../UtilFunctions/UtilWebGoToPageFn.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs index 3245a802..9565e217 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs @@ -5,5 +5,5 @@ public class WebBrowsingSettings public string Driver { get; set; } = "Playwright"; public bool Headless { get; set; } // Default timeout in milliseconds - public float DefaultTimeOut { get; set; } = 30000; + public float DefaultTimeout { get; set; } = 30000; } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs index 9e93b2a7..fe69f9d1 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs @@ -36,7 +36,7 @@ public class GoToPageFn : IFunctionCallback }, new PageActionArgs { Url = url, - Timeout = _webDriver.DefaultTimeOut + Timeout = _webDriver.DefaultTimeout }); message.Content = result.IsSuccess ? $"Page {url} is open." : $"Page {url} open failed. {result.Message}"; diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs index beb412b5..0beb80fc 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs @@ -41,7 +41,7 @@ public class OpenBrowserFn : IFunctionCallback result = await _browser.GoToPage(msgInfo, new PageActionArgs { Url = url, - Timeout = _webDriver.DefaultTimeOut + Timeout = _webDriver.DefaultTimeout }); if (result.IsSuccess) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs index f62a6ae9..a29af212 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs @@ -24,7 +24,7 @@ public class UtilWebGoToPageFn : IFunctionCallback PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); var _webDriver = _services.GetRequiredService(); - args.Timeout = _webDriver.DefaultTimeOut; + args.Timeout = _webDriver.DefaultTimeout; args.WaitForNetworkIdle = false; args.WaitTime = 5; args.OpenNewTab = true;