Skip to content

Commit 0cd2863

Browse files
author
Jicheng Lu
committed
Merge branch 'master' of https://github.com/SciSharp/BotSharp
2 parents 85cf382 + b9e9d58 commit 0cd2863

File tree

8 files changed

+23
-13
lines changed

8 files changed

+23
-13
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<PackageVersion Include="LLamaSharp" Version="0.20.0" />
5555
<PackageVersion Include="FaissMask" Version="0.2.0" />
5656
<PackageVersion Include="FastText.NetWrapper" Version="1.3.0" />
57-
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
57+
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
5858
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
5959
<PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
6060
<PackageVersion Include="Docnet.Core" Version="2.7.0-alpha.1" />

src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ public class WebBrowsingSettings
44
{
55
public string Driver { get; set; } = "Playwright";
66
public bool Headless { get; set; }
7+
// Default timeout in milliseconds
8+
public float DefaultTimeout { get; set; } = 30000;
79
}

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ private async Task HandleUserDtmfReceived()
233233
}
234234

235235
await _completer.InsertConversationItem(message);
236-
await _completer.TriggerModelInference("Reply based on the user input");
236+
var instruction = await _completer.UpdateSession(_conn);
237+
await _completer.TriggerModelInference($"{instruction}\r\n\r\nReply based on the user input: {message.Content}");
237238
}
238239

239240
private async Task HandleUserDisconnected()

src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAIChatCompletionProvider.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio
2727
private readonly IChatClient _client;
2828
private readonly ILogger<MicrosoftExtensionsAIChatCompletionProvider> _logger;
2929
private readonly IServiceProvider _services;
30-
private List<string> renderedInstructions = [];
3130
private string? _model;
3231

3332
/// <summary>
@@ -46,7 +45,7 @@ public MicrosoftExtensionsAIChatCompletionProvider(
4645

4746
/// <inheritdoc/>
4847
public string Provider => "microsoft.extensions.ai";
49-
public string Model => _model;
48+
public string Model => _model ?? "";
5049

5150
/// <inheritdoc/>
5251
public void SetModelName(string model) => _model = model;
@@ -56,7 +55,7 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
5655
{
5756
// Before chat completion hook
5857
var hooks = _services.GetServices<IContentGeneratingHook>().ToArray();
59-
renderedInstructions = [];
58+
List<string> renderedInstructions = [];
6059
await Task.WhenAll(hooks.Select(hook => hook.BeforeGenerating(agent, conversations)));
6160

6261
// Configure options
@@ -145,13 +144,13 @@ public async Task<RoleDialogModel> GetChatCompletions(Agent agent, List<RoleDial
145144

146145
var completion = await _client.GetResponseAsync(messages);
147146

148-
RoleDialogModel result = new(AgentRole.Assistant, string.Concat(completion.Message.Contents.OfType<TextContent>()))
147+
RoleDialogModel result = new(AgentRole.Assistant, completion.Text)
149148
{
150149
CurrentAgentId = agent.Id,
151-
RenderedInstruction = string.Join("\r\n", renderedInstructions)
150+
//RenderedInstruction = renderedInstructions,
152151
};
153152

154-
if (completion.Message.Contents.OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
153+
if (completion.Messages.SelectMany(m => m.Contents).OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
155154
{
156155
result.Role = AgentRole.Function;
157156
result.MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty;

src/Plugins/BotSharp.Plugin.MicrosoftExtensionsAI/MicrosoftExtensionsAITextCompletionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task<string> GetCompletion(string text, string agentId, string mess
5151

5252
_tokenStatistics.StartTimer();
5353
var completion = await _chatClient.GetResponseAsync(text);
54-
var result = string.Concat(completion.Message.Contents.OfType<TextContent>());
54+
var result = completion.Text;
5555
_tokenStatistics.StopTimer();
5656

5757
// After chat completion hook

src/Plugins/BotSharp.Plugin.WebDriver/Functions/GoToPageFn.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Abstraction.Browsing.Settings;
2+
13
namespace BotSharp.Plugin.WebDriver.Functions;
24

35
public class GoToPageFn : IFunctionCallback
@@ -25,15 +27,16 @@ public async Task<bool> Execute(RoleDialogModel message)
2527
var url = webDriverService.ReplaceToken(args.Url);
2628

2729
url = url.Replace("https://https://", "https://");
28-
30+
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
2931
var result = await _browser.GoToPage(new MessageInfo
3032
{
3133
AgentId = message.CurrentAgentId,
3234
ContextId = convService.ConversationId,
3335
MessageId = message.MessageId
3436
}, new PageActionArgs
3537
{
36-
Url = url
38+
Url = url,
39+
Timeout = _webDriver.DefaultTimeout
3740
});
3841
message.Content = result.IsSuccess ? $"Page {url} is open." : $"Page {url} open failed. {result.Message}";
3942

src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task<bool> Execute(RoleDialogModel message)
2626

2727
var webDriverService = _services.GetRequiredService<WebDriverService>();
2828
var url = webDriverService.ReplaceToken(args.Url);
29-
29+
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
3030
url = url.Replace("https://https://", "https://");
3131
var msgInfo = new MessageInfo
3232
{
@@ -40,7 +40,8 @@ public async Task<bool> Execute(RoleDialogModel message)
4040
});
4141
result = await _browser.GoToPage(msgInfo, new PageActionArgs
4242
{
43-
Url = url
43+
Url = url,
44+
Timeout = _webDriver.DefaultTimeout
4445
});
4546

4647
if (result.IsSuccess)

src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebGoToPageFn.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Abstraction.Browsing.Settings;
2+
13
namespace BotSharp.Plugin.WebDriver.UtilFunctions;
24

35
public class UtilWebGoToPageFn : IFunctionCallback
@@ -21,6 +23,8 @@ public async Task<bool> Execute(RoleDialogModel message)
2123
{
2224
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
2325
});
26+
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
27+
args.Timeout = _webDriver.DefaultTimeout;
2428
args.WaitForNetworkIdle = false;
2529
args.WaitTime = 5;
2630
args.OpenNewTab = true;

0 commit comments

Comments
 (0)