diff --git a/src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs b/src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs index 79711cb63..4b6364409 100644 --- a/src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs +++ b/src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs @@ -15,9 +15,6 @@ limitations under the License. ******************************************************************************/ using BotSharp.Core.Infrastructures; -using NetTopologySuite.Index.KdTree; -using Newtonsoft.Json.Linq; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace BotSharp.Core.SideCar.Services; diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 4c8178d84..50bfa5303 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -14,8 +14,6 @@ You may obtain a copy of the License at limitations under the License. ******************************************************************************/ -using BotSharp.Abstraction.Conversations.Enums; -using BotSharp.Abstraction.Hooks; using BotSharp.Abstraction.Options; using BotSharp.Abstraction.SideCar; diff --git a/src/Infrastructure/BotSharp.Core/Demo/Functions/GetWeatherFn.cs b/src/Infrastructure/BotSharp.Core/Demo/Functions/GetWeatherFn.cs index 8b0411fe8..7677af206 100644 --- a/src/Infrastructure/BotSharp.Core/Demo/Functions/GetWeatherFn.cs +++ b/src/Infrastructure/BotSharp.Core/Demo/Functions/GetWeatherFn.cs @@ -37,11 +37,11 @@ public async Task Execute(RoleDialogModel message) await Task.Delay(1500); #if DEBUG - var temp = RoleDialogModel.From(message, AgentRole.Assistant, $"Here is your weather in {args?.City}"); + var intermediateMsg = RoleDialogModel.From(message, AgentRole.Assistant, $"Here is your weather in {args?.City}"); messageHub.Push(new() { EventName = ChatEvent.OnIntermediateMessageReceivedFromAssistant, - Data = temp, + Data = intermediateMsg, RefId = conv.ConversationId, SaveDataToDb = true }); diff --git a/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs b/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs index e2588c6cf..1ee4b1646 100644 --- a/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs +++ b/src/Infrastructure/BotSharp.Core/MessageHub/Observers/ConversationObserver.cs @@ -30,6 +30,8 @@ public override void OnError(Exception error) public override void OnNext(HubObserveData value) { var conv = _services.GetRequiredService(); + var storage = _services.GetRequiredService(); + var routeCtx = _services.GetRequiredService(); if (value.EventName == ChatEvent.OnIndicationReceived) { @@ -41,5 +43,16 @@ public override void OnNext(HubObserveData value) func(value).ConfigureAwait(false).GetAwaiter().GetResult(); } } + else if (value.EventName == ChatEvent.OnIntermediateMessageReceivedFromAssistant) + { + var dialogs = routeCtx.GetDialogs(); + dialogs.Add(value.Data); + routeCtx.SetDialogs(dialogs); + + if (value.SaveDataToDb) + { + storage.Append(conv.ConversationId, value.Data); + } + } } } diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs index 3d8bf7886..bf0fee9a6 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Observers/ChatHubObserver.cs @@ -140,12 +140,6 @@ public override void OnNext(HubObserveData value) Role = AgentRole.Assistant } }; - - if (value.SaveDataToDb) - { - var storage = _services.GetRequiredService(); - storage.Append(conv.ConversationId, message); - } break; }