Merge branch 'SciSharp:master' into master
This commit is contained in:
commit
3a2d4bc3de
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ namespace BotSharp.Abstraction.Browsing.Settings;
|
|||
public class WebBrowsingSettings
|
||||
{
|
||||
public string Driver { get; set; } = "Playwright";
|
||||
public bool Headless { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ namespace BotSharp.Abstraction.Tasks.Models;
|
|||
|
||||
public class AgentTask
|
||||
{
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
|
||||
|
|
@ -19,9 +22,15 @@ public class AgentTask
|
|||
/// </summary>
|
||||
public string Status { get; set; } = TaskStatus.New;
|
||||
|
||||
public DateTime? LastExecutedDateTime { get; set; }
|
||||
public DateTime? NextExecutionDateTime { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public DateTime? LastExecutionTime { get; set; }
|
||||
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
public DateTime UpdatedDateTime { get; set; }
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public DateTime? NextExecutionTime { get; set; }
|
||||
|
||||
[JsonPropertyName("created_time")]
|
||||
public DateTime CreatedTime { get; set; }
|
||||
|
||||
[JsonPropertyName("updated_time")]
|
||||
public DateTime UpdatedTime { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class CrontabService : ICrontabService, ITaskFeeder
|
|||
Status = TaskStatus.Scheduled,
|
||||
Enabled = !x.Disabled,
|
||||
Description = cron.Description,
|
||||
LastExecutedDateTime = cron.LastExecutionTime
|
||||
LastExecutionTime = cron.LastExecutionTime
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -185,8 +185,8 @@ public partial class AgentService
|
|||
Enabled = parsedTask.Enabled,
|
||||
Content = parsedTask.Content,
|
||||
AgentId = agentId,
|
||||
CreatedDateTime = parsedTask.CreatedDateTime,
|
||||
UpdatedDateTime = parsedTask.UpdatedDateTime
|
||||
CreatedTime = parsedTask.CreatedTime,
|
||||
UpdatedTime = parsedTask.UpdatedTime
|
||||
};
|
||||
tasks.Add(task);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,8 +129,8 @@ public partial class FileRepository
|
|||
Name = task.Name,
|
||||
Description = task.Description,
|
||||
Enabled = task.Enabled,
|
||||
CreatedDateTime = DateTime.UtcNow,
|
||||
UpdatedDateTime = DateTime.UtcNow
|
||||
CreatedTime = DateTime.UtcNow,
|
||||
UpdatedTime = DateTime.UtcNow
|
||||
};
|
||||
|
||||
var fileContent = BuildAgentTaskFileContent(metaData, task.Content);
|
||||
|
|
@ -163,8 +163,8 @@ public partial class FileRepository
|
|||
Name = parsedTask.Name,
|
||||
Description = parsedTask.Description,
|
||||
Enabled = parsedTask.Enabled,
|
||||
CreatedDateTime = parsedTask.CreatedDateTime,
|
||||
UpdatedDateTime = DateTime.UtcNow
|
||||
CreatedTime = parsedTask.CreatedTime,
|
||||
UpdatedTime = DateTime.UtcNow
|
||||
};
|
||||
var content = parsedTask.Content;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class AgentTaskService : IAgentTaskService
|
|||
|
||||
return new PagedItems<AgentTask>
|
||||
{
|
||||
Items = items.OrderByDescending(x => x.UpdatedDateTime)
|
||||
Items = items.OrderByDescending(x => x.UpdatedTime)
|
||||
.Skip(filter.Pager.Offset).Take(filter.Pager.Size),
|
||||
Count = items.Count()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public class InstructionLogHook : InstructHookBase
|
|||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
|
||||
var user = db.GetUserById(_user.Id);
|
||||
var templateName = response.TemplateName ?? state.GetState("instruct_template_name") ?? null;
|
||||
|
||||
db.SaveInstructionLogs(new List<InstructionLogModel>
|
||||
{
|
||||
new InstructionLogModel
|
||||
|
|
@ -39,7 +41,7 @@ public class InstructionLogHook : InstructHookBase
|
|||
AgentId = response.AgentId,
|
||||
Provider = response.Provider,
|
||||
Model = response.Model,
|
||||
TemplateName = response.TemplateName,
|
||||
TemplateName = !string.IsNullOrWhiteSpace(templateName) ? templateName : null,
|
||||
UserMessage = response.UserMessage,
|
||||
SystemInstruction = response.SystemInstruction,
|
||||
CompletionText = response.CompletionText,
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ public class AgentTaskViewModel
|
|||
|
||||
public string Status { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("created_datetime")]
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
[JsonPropertyName("created_time")]
|
||||
public DateTime CreatedTime { get; set; }
|
||||
|
||||
[JsonPropertyName("updated_datetime")]
|
||||
public DateTime UpdatedDateTime { get; set; }
|
||||
[JsonPropertyName("updated_time")]
|
||||
public DateTime UpdatedTime { get; set; }
|
||||
|
||||
[JsonPropertyName("agent_id")]
|
||||
public string AgentId { get; set; } = null!;
|
||||
|
|
@ -37,8 +37,8 @@ public class AgentTaskViewModel
|
|||
AgentId = task.AgentId,
|
||||
AgentName = task.Agent?.Name,
|
||||
Status = task.Status,
|
||||
CreatedDateTime = task.CreatedDateTime,
|
||||
UpdatedDateTime = task.UpdatedDateTime
|
||||
CreatedTime = task.CreatedTime,
|
||||
UpdatedTime = task.UpdatedTime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ public class AgentTaskDocument : MongoBase
|
|||
Enabled = model.Enabled,
|
||||
AgentId = model.AgentId,
|
||||
Status = model.Status,
|
||||
CreatedDateTime = model.CreatedTime,
|
||||
UpdatedDateTime = model.UpdatedTime
|
||||
CreatedTime = model.CreatedTime,
|
||||
UpdatedTime = model.UpdatedTime
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -38,8 +38,8 @@ public class AgentTaskDocument : MongoBase
|
|||
Enabled = model.Enabled,
|
||||
AgentId = model.AgentId,
|
||||
Status = model.Status,
|
||||
CreatedTime = model.CreatedDateTime,
|
||||
UpdatedTime = model.UpdatedDateTime
|
||||
CreatedTime = model.CreatedTime,
|
||||
UpdatedTime = model.UpdatedTime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
Action<RoleDialogModel> onInputAudioTranscriptionCompleted,
|
||||
Action onUserInterrupted)
|
||||
{
|
||||
var buffer = new byte[1024 * 16];
|
||||
var buffer = new byte[1024 * 32];
|
||||
WebSocketReceiveResult result;
|
||||
|
||||
do
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Azure;
|
||||
using BotSharp.Abstraction.Browsing.Settings;
|
||||
using System.IO;
|
||||
|
||||
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
||||
|
|
@ -33,9 +34,10 @@ public class PlaywrightInstance : IDisposable
|
|||
|
||||
public async Task<IBrowserContext> GetContext(string ctxId)
|
||||
{
|
||||
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
|
||||
if (!_contexts.ContainsKey(ctxId))
|
||||
{
|
||||
await InitContext(ctxId, new BrowserActionArgs());
|
||||
await InitContext(ctxId, new BrowserActionArgs() { Headless = _webDriver.Headless });
|
||||
}
|
||||
return _contexts[ctxId];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using BotSharp.Abstraction.Browsing.Settings;
|
||||
|
||||
namespace BotSharp.Plugin.WebDriver.Functions;
|
||||
|
||||
public class OpenBrowserFn : IFunctionCallback
|
||||
|
|
@ -6,12 +8,15 @@ public class OpenBrowserFn : IFunctionCallback
|
|||
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IWebBrowser _browser;
|
||||
private readonly WebBrowsingSettings _webBrowsingSettings;
|
||||
|
||||
public OpenBrowserFn(IServiceProvider services,
|
||||
IWebBrowser browser)
|
||||
IWebBrowser browser,
|
||||
WebBrowsingSettings webBrowsingSettings)
|
||||
{
|
||||
_services = services;
|
||||
_browser = browser;
|
||||
_webBrowsingSettings = webBrowsingSettings;
|
||||
}
|
||||
|
||||
public async Task<bool> Execute(RoleDialogModel message)
|
||||
|
|
@ -31,7 +36,7 @@ public class OpenBrowserFn : IFunctionCallback
|
|||
};
|
||||
var result = await _browser.LaunchBrowser(msgInfo, new BrowserActionArgs
|
||||
{
|
||||
Headless = false
|
||||
Headless = _webBrowsingSettings.Headless
|
||||
});
|
||||
result = await _browser.GoToPage(msgInfo, new PageActionArgs
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue