diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs index 337d63c66..d50bced0e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingContext.cs @@ -31,6 +31,7 @@ public interface IRoutingContext void ResetAgentStack(); void SetDialogs(List dialogs); + void AddDialogs(List dialogs); List GetDialogs(); void ResetDialogs(); } diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs index a2de1940f..d2af898b1 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs @@ -13,10 +13,10 @@ public async Task> SelectMessageFiles(string conve return Enumerable.Empty(); } - var routeContext = _services.GetRequiredService(); + var routingCtx = _services.GetRequiredService(); var convService = _services.GetRequiredService(); - var dialogs = routeContext.GetDialogs(); + var dialogs = routingCtx.GetDialogs(); if (dialogs.IsNullOrEmpty()) { dialogs = convService.GetDialogHistory(fromBreakpoint: options.FromBreakpoint); diff --git a/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs b/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs index 1ee4b1646..55bcfe3e1 100644 --- a/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs +++ b/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs @@ -31,12 +31,12 @@ public override void OnNext(HubObserveData value) { var conv = _services.GetRequiredService(); var storage = _services.GetRequiredService(); - var routeCtx = _services.GetRequiredService(); + var routingCtx = _services.GetRequiredService(); if (value.EventName == ChatEvent.OnIndicationReceived) { #if DEBUG - _logger.LogCritical($"Receiving {value.EventName} ({value.Data.Indication}) in {nameof(ConversationObserver)} - {conv.ConversationId}"); + _logger.LogCritical($"[{nameof(ConversationObserver)}]: Receive {value.EventName} => {value.Data.Indication} ({conv.ConversationId})"); #endif if (_listeners.TryGetValue(value.EventName, out var func) && func != null) { @@ -45,10 +45,10 @@ public override void OnNext(HubObserveData value) } else if (value.EventName == ChatEvent.OnIntermediateMessageReceivedFromAssistant) { - var dialogs = routeCtx.GetDialogs(); - dialogs.Add(value.Data); - routeCtx.SetDialogs(dialogs); - +#if DEBUG + _logger.LogCritical($"[{nameof(ConversationObserver)}]: Receive {value.EventName} => {value.Data.Content} ({conv.ConversationId})"); +#endif + routingCtx.AddDialogs([value.Data]); if (value.SaveDataToDb) { storage.Append(conv.ConversationId, value.Data); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs index 929289aa5..4212c08c5 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs @@ -269,12 +269,20 @@ public void ResetAgentStack() public void SetDialogs(List dialogs) { - _dialogs = dialogs ?? []; + _dialogs = new List(dialogs ?? []); + } + + public void AddDialogs(List dialogs) + { + var items = new List(dialogs ?? []); + _dialogs ??= []; + _dialogs.AddRange(items); } public List GetDialogs() { - return _dialogs ?? []; + _dialogs ??= []; + return new List(_dialogs); } public void ResetDialogs() diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs index 00c665527..e0175a70d 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs @@ -77,7 +77,7 @@ public async Task InvokeAgent( message.IsStreaming = response.IsStreaming; message.MessageLabel = response.MessageLabel; dialogs.Add(message); - Context.SetDialogs(dialogs); + Context.AddDialogs([message]); } return true; @@ -106,10 +106,11 @@ private async Task InvokeFunction( var responseTemplate = await templateService.RenderFunctionResponse(message.CurrentAgentId, message); if (!string.IsNullOrEmpty(responseTemplate)) { - dialogs.Add(RoleDialogModel.From(message, + var msg = RoleDialogModel.From(message, role: AgentRole.Assistant, - content: responseTemplate)); - Context.SetDialogs(dialogs); + content: responseTemplate); + dialogs.Add(msg); + Context.AddDialogs([msg]); } else { @@ -119,7 +120,7 @@ private async Task InvokeFunction( content: message.Content); dialogs.Add(msg); - Context.SetDialogs(dialogs); + Context.AddDialogs([msg]); // Send to Next LLM var curAgentId = routing.Context.GetCurrentAgentId(); @@ -128,10 +129,11 @@ private async Task InvokeFunction( } else { - dialogs.Add(RoleDialogModel.From(message, + var msg = RoleDialogModel.From(message, role: AgentRole.Assistant, - content: message.Content)); - Context.SetDialogs(dialogs); + content: message.Content); + dialogs.Add(msg); + Context.AddDialogs([msg]); } return true; diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs index bf0fee9a6..86ecc84e8 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs @@ -3,6 +3,7 @@ using BotSharp.Abstraction.MessageHub.Models; using BotSharp.Abstraction.MessageHub.Observers; using BotSharp.Abstraction.SideCar; +using BotSharp.Core.MessageHub.Observers; using System.Runtime.CompilerServices; namespace BotSharp.Plugin.ChatHub.Observers; @@ -118,7 +119,7 @@ public override void OnNext(HubObserveData value) }; #if DEBUG - _logger.LogCritical($"Receiving {value.EventName} ({value.Data.Indication}) in {nameof(ChatHubObserver)} - {conv.ConversationId}"); + _logger.LogCritical($"[{nameof(ChatHubObserver)}]: Receive {value.EventName} => {value.Data.Indication} ({conv.ConversationId})"); #endif break; case ChatEvent.OnIntermediateMessageReceivedFromAssistant: diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs index 8d491ab3b..6305b0a5d 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Services/MySqlService.cs @@ -1,8 +1,8 @@ -using MySql.Data.MySqlClient; -using Newtonsoft.Json; -using NPOI.SS.UserModel; using System.Data; using System.Text.RegularExpressions; +using Newtonsoft.Json; +using MySql.Data.MySqlClient; +using NPOI.SS.UserModel; namespace BotSharp.Plugin.ExcelHandler.Services; diff --git a/src/Plugins/BotSharp.Plugin.ExcelHandler/Settings/ExcelHandlerSettings.cs b/src/Plugins/BotSharp.Plugin.ExcelHandler/Settings/ExcelHandlerSettings.cs index d68af4b3d..60cf68b13 100644 --- a/src/Plugins/BotSharp.Plugin.ExcelHandler/Settings/ExcelHandlerSettings.cs +++ b/src/Plugins/BotSharp.Plugin.ExcelHandler/Settings/ExcelHandlerSettings.cs @@ -7,6 +7,9 @@ public class ExcelHandlerSettings public class DatabaseSettings { + /// + /// Database: mysql, sqlite + /// public string Provider { get; set; } = "mysql"; public string ConnectionString { get; set; } } \ No newline at end of file