diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/TranslationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/TranslationController.cs index 7845e8cf6..a4fa2b50c 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/TranslationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/TranslationController.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Options; +using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Translation; using BotSharp.OpenAPI.ViewModels.Translations; @@ -21,8 +22,8 @@ public TranslationController(IServiceProvider services, [HttpPost("/translate")] public async Task Translate([FromBody] TranslationRequestModel model) { - var agentService = _services.GetRequiredService(); - var agent = await agentService.LoadAgent(BuiltInAgentId.AIAssistant); + var db = _services.GetRequiredService(); + var agent = db.GetAgent(BuiltInAgentId.AIAssistant); var translator = _services.GetRequiredService(); var states = _services.GetRequiredService(); states.SetState("max_tokens", "8192"); @@ -36,8 +37,8 @@ public async Task Translate([FromBody] TranslationRequ [HttpPost("/translate/long-text")] public async Task SendMessageSse([FromBody] TranslationLongTextRequestModel model) { - var agentService = _services.GetRequiredService(); - var agent = await agentService.LoadAgent(BuiltInAgentId.AIAssistant); + var db = _services.GetRequiredService(); + var agent = db.GetAgent(BuiltInAgentId.AIAssistant); var translator = _services.GetRequiredService(); Response.StatusCode = 200; diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs index abbe89ddd..43bc839ae 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs @@ -25,11 +25,11 @@ public WelcomeHook(IServiceProvider services, public override async Task OnUserAgentConnectedInitially(Conversation conversation) { - var agentService = _services.GetRequiredService(); - var agent = await agentService.LoadAgent(conversation.AgentId); + var db = _services.GetRequiredService(); + var agent = db.GetAgent(conversation.AgentId); // Check if the Welcome template exists. - var welcomeTemplate = agent.Templates?.FirstOrDefault(x => x.Name == ".welcome"); + var welcomeTemplate = agent?.Templates?.FirstOrDefault(x => x.Name == ".welcome"); if (welcomeTemplate != null) { // Render template