This commit is contained in:
Jicheng Lu 2025-03-12 10:15:30 -05:00
commit 0cd2863cb0
8 changed files with 23 additions and 13 deletions

View file

@ -54,7 +54,7 @@
<PackageVersion Include="LLamaSharp" Version="0.20.0" />
<PackageVersion Include="FaissMask" Version="0.2.0" />
<PackageVersion Include="FastText.NetWrapper" Version="1.3.0" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.1.0" />
<PackageVersion Include="Docnet.Core" Version="2.7.0-alpha.1" />

View file

@ -4,4 +4,6 @@ public class WebBrowsingSettings
{
public string Driver { get; set; } = "Playwright";
public bool Headless { get; set; }
// Default timeout in milliseconds
public float DefaultTimeout { get; set; } = 30000;
}

View file

@ -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()

View file

@ -27,7 +27,6 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio
private readonly IChatClient _client;
private readonly ILogger<MicrosoftExtensionsAIChatCompletionProvider> _logger;
private readonly IServiceProvider _services;
private List<string> renderedInstructions = [];
private string? _model;
/// <summary>
@ -46,7 +45,7 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio
/// <inheritdoc/>
public string Provider => "microsoft.extensions.ai";
public string Model => _model;
public string Model => _model ?? "";
/// <inheritdoc/>
public void SetModelName(string model) => _model = model;
@ -56,7 +55,7 @@ public sealed class MicrosoftExtensionsAIChatCompletionProvider : IChatCompletio
{
// Before chat completion hook
var hooks = _services.GetServices<IContentGeneratingHook>().ToArray();
renderedInstructions = [];
List<string> 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<TextContent>()))
RoleDialogModel result = new(AgentRole.Assistant, completion.Text)
{
CurrentAgentId = agent.Id,
RenderedInstruction = string.Join("\r\n", renderedInstructions)
//RenderedInstruction = renderedInstructions,
};
if (completion.Message.Contents.OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
if (completion.Messages.SelectMany(m => m.Contents).OfType<FunctionCallContent>().FirstOrDefault() is { } fcc)
{
result.Role = AgentRole.Function;
result.MessageId = conversations.LastOrDefault()?.MessageId ?? string.Empty;

View file

@ -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<TextContent>());
var result = completion.Text;
_tokenStatistics.StopTimer();
// After chat completion hook

View file

@ -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<WebBrowsingSettings>();
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}";

View file

@ -26,7 +26,7 @@ public class OpenBrowserFn : IFunctionCallback
var webDriverService = _services.GetRequiredService<WebDriverService>();
var url = webDriverService.ReplaceToken(args.Url);
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
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)

View file

@ -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<WebBrowsingSettings>();
args.Timeout = _webDriver.DefaultTimeout;
args.WaitForNetworkIdle = false;
args.WaitTime = 5;
args.OpenNewTab = true;