Merge pull request #821 from iceljc/master

refine agent load
This commit is contained in:
iceljc 2025-01-08 16:06:21 -06:00 committed by GitHub
commit 43eb549bd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View file

@ -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 class TranslationController : ControllerBase
[HttpPost("/translate")]
public async Task<TranslationResponseModel> Translate([FromBody] TranslationRequestModel model)
{
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(BuiltInAgentId.AIAssistant);
var db = _services.GetRequiredService<IBotSharpRepository>();
var agent = db.GetAgent(BuiltInAgentId.AIAssistant);
var translator = _services.GetRequiredService<ITranslationService>();
var states = _services.GetRequiredService<IConversationStateService>();
states.SetState("max_tokens", "8192");
@ -36,8 +37,8 @@ public class TranslationController : ControllerBase
[HttpPost("/translate/long-text")]
public async Task SendMessageSse([FromBody] TranslationLongTextRequestModel model)
{
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(BuiltInAgentId.AIAssistant);
var db = _services.GetRequiredService<IBotSharpRepository>();
var agent = db.GetAgent(BuiltInAgentId.AIAssistant);
var translator = _services.GetRequiredService<ITranslationService>();
Response.StatusCode = 200;

View file

@ -25,11 +25,11 @@ public class WelcomeHook : ConversationHookBase
public override async Task OnUserAgentConnectedInitially(Conversation conversation)
{
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(conversation.AgentId);
var db = _services.GetRequiredService<IBotSharpRepository>();
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