Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public interface IRoutingContext
void ResetAgentStack();

void SetDialogs(List<RoleDialogModel> dialogs);
void AddDialogs(List<RoleDialogModel> dialogs);
List<RoleDialogModel> GetDialogs();
void ResetDialogs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public async Task<IEnumerable<MessageFileModel>> SelectMessageFiles(string conve
return Enumerable.Empty<MessageFileModel>();
}

var routeContext = _services.GetRequiredService<IRoutingContext>();
var routingCtx = _services.GetRequiredService<IRoutingContext>();
var convService = _services.GetRequiredService<IConversationService>();

var dialogs = routeContext.GetDialogs();
var dialogs = routingCtx.GetDialogs();
if (dialogs.IsNullOrEmpty())
{
dialogs = convService.GetDialogHistory(fromBreakpoint: options.FromBreakpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public override void OnNext(HubObserveData<RoleDialogModel> value)
{
var conv = _services.GetRequiredService<IConversationService>();
var storage = _services.GetRequiredService<IConversationStorage>();
var routeCtx = _services.GetRequiredService<IRoutingContext>();
var routingCtx = _services.GetRequiredService<IRoutingContext>();

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)
{
Expand All @@ -45,10 +45,10 @@ public override void OnNext(HubObserveData<RoleDialogModel> 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);
Expand Down
12 changes: 10 additions & 2 deletions src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,20 @@ public void ResetAgentStack()

public void SetDialogs(List<RoleDialogModel> dialogs)
{
_dialogs = dialogs ?? [];
_dialogs = new List<RoleDialogModel>(dialogs ?? []);
}

public void AddDialogs(List<RoleDialogModel> dialogs)
{
var items = new List<RoleDialogModel>(dialogs ?? []);
_dialogs ??= [];
_dialogs.AddRange(items);
}

public List<RoleDialogModel> GetDialogs()
{
return _dialogs ?? [];
_dialogs ??= [];
return new List<RoleDialogModel>(_dialogs);
}

public void ResetDialogs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task<bool> InvokeAgent(
message.IsStreaming = response.IsStreaming;
message.MessageLabel = response.MessageLabel;
dialogs.Add(message);
Context.SetDialogs(dialogs);
Context.AddDialogs([message]);
}

return true;
Expand Down Expand Up @@ -106,10 +106,11 @@ private async Task<bool> 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
{
Expand All @@ -119,7 +120,7 @@ private async Task<bool> InvokeFunction(
content: message.Content);

dialogs.Add(msg);
Context.SetDialogs(dialogs);
Context.AddDialogs([msg]);

// Send to Next LLM
var curAgentId = routing.Context.GetCurrentAgentId();
Expand All @@ -128,10 +129,11 @@ private async Task<bool> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +119,7 @@ public override void OnNext(HubObserveData<RoleDialogModel> 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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class ExcelHandlerSettings

public class DatabaseSettings
{
/// <summary>
/// Database: mysql, sqlite
/// </summary>
public string Provider { get; set; } = "mysql";
public string ConnectionString { get; set; }
}
Loading