From 8b135e8c321b1acbf583260e4f0beb6c64a27be4 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 21 Sep 2023 11:23:43 -0500 Subject: [PATCH] Add router name. --- Directory.Build.props | 2 +- .../Routing/Settings/RoutingSettings.cs | 2 ++ .../BotSharp.Core/Routing/RoutingService.cs | 1 + .../BotSharp.OpenAPI/Controllers/AgentController.cs | 13 ++++++++++++- src/WebStarter/appsettings.json | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 09841a41..d9f62fe9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ 10.0 ..\..\..\packages - 0.14.2 + 0.14.3 true \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Settings/RoutingSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Settings/RoutingSettings.cs index 2ab88233..050868ba 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Settings/RoutingSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Settings/RoutingSettings.cs @@ -7,6 +7,8 @@ public class RoutingSettings /// public string RouterId { get; set; } = string.Empty; + public string RouteName { get; set; } = "Router"; + public bool EnableReasoning { get; set; } = false; public string Provider { get; set; } = string.Empty; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 160708fa..9fd398be 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -210,6 +210,7 @@ public class RoutingService : IRoutingService var router = new Agent() { Id = _settings.RouterId, + Name = _settings.RouteName }; var agents = db.Agents.Where(x => !x.Disabled && x.AllowRouting).ToArray(); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 7baaa16a..b75cb239 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -1,5 +1,8 @@ using BotSharp.Abstraction.Agents.Enums; +using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.ApiAdapters; +using BotSharp.Abstraction.Routing; +using BotSharp.Abstraction.Routing.Settings; using BotSharp.OpenAPI.ViewModels.Agents; namespace BotSharp.OpenAPI.Controllers; @@ -9,15 +12,23 @@ namespace BotSharp.OpenAPI.Controllers; public class AgentController : ControllerBase, IApiAdapter { private readonly IAgentService _agentService; - public AgentController(IAgentService agentService) + private readonly IServiceProvider _services; + + public AgentController(IAgentService agentService, IServiceProvider services) { _agentService = agentService; + _services = services; } [HttpGet("/agents")] public async Task> GetAgents() { var agents = await _agentService.GetAgents(); + + // Add the router as agent + var routing = _services.GetRequiredService(); + agents.Add(routing.LoadRouter()); + return agents.Select(x => AgentViewModel.FromAgent(x)).ToList(); } diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index cb89eecd..acfc800a 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -15,6 +15,7 @@ "Router": { "RouterId": "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a", + "RouterName": "PizzaBot", "EnableReasoning": false, "Model": "gpt-3.5" },