Merge pull request #1170 from iceljc/features/refine-model-settings

refine routing context
This commit is contained in:
iceljc 2025-09-19 11:52:29 -05:00 committed by GitHub
commit 7a7fc0bf3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 22 deletions

View file

@ -31,6 +31,7 @@ public interface IRoutingContext
void ResetAgentStack();
void SetDialogs(List<RoleDialogModel> dialogs);
void AddDialogs(List<RoleDialogModel> dialogs);
List<RoleDialogModel> GetDialogs();
void ResetDialogs();
}

View file

@ -13,10 +13,10 @@ public partial class FileInstructService
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);

View file

@ -31,12 +31,12 @@ public class ConversationObserver : BotSharpObserverBase<HubObserveData<RoleDial
{
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)
{
@ -45,10 +45,10 @@ public class ConversationObserver : BotSharpObserverBase<HubObserveData<RoleDial
}
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);

View file

@ -269,12 +269,20 @@ public class RoutingContext : IRoutingContext
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()

View file

@ -77,7 +77,7 @@ public partial class RoutingService
message.IsStreaming = response.IsStreaming;
message.MessageLabel = response.MessageLabel;
dialogs.Add(message);
Context.SetDialogs(dialogs);
Context.AddDialogs([message]);
}
return true;
@ -106,10 +106,11 @@ public partial class RoutingService
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 @@ public partial class RoutingService
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 @@ public partial class RoutingService
}
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;

View file

@ -3,6 +3,7 @@ using BotSharp.Abstraction.Conversations.Enums;
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 class ChatHubObserver : BotSharpObserverBase<HubObserveData<RoleDialogMod
};
#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:

View file

@ -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;

View file

@ -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; }
}