diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs index 4eb44ae4a..656b397d8 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs @@ -1,4 +1,3 @@ -using BotSharp.Abstraction.Loggers.Models; using BotSharp.Abstraction.Repositories.Filters; namespace BotSharp.Abstraction.Conversations; @@ -53,7 +52,7 @@ Task SendMessage(string agentId, /// Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates); - Task GetConversationSummary(IEnumerable conversationId); + Task GetConversationSummary(ConversationSummaryModel model); Task GetConversationRecordOrCreateNew(string agentId); diff --git a/src/Infrastructure/BotSharp.Abstraction/Models/ConversationSummaryModel.cs b/src/Infrastructure/BotSharp.Abstraction/Models/ConversationSummaryModel.cs new file mode 100644 index 000000000..00860e2ef --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Models/ConversationSummaryModel.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; + +namespace BotSharp.Abstraction.Models; + +public class ConversationSummaryModel +{ + [JsonPropertyName("conversation_ids")] + public IEnumerable ConversationIds { get; set; } = new List(); + + private string _agentId; + + [JsonPropertyName("agent_id")] + public string AgentId + { + get => _agentId ?? BuiltInAgentId.AIAssistant; + set => _agentId = value; + } + + private string _templateName; + + [JsonPropertyName("template_name")] + public string TemplateName + { + get => _templateName ?? "conversation.summary"; + set => _templateName = value; + } +} diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs index 88d3a52d1..ba141e08a 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs @@ -1,20 +1,21 @@ using BotSharp.Abstraction.Conversations.Enums; using BotSharp.Abstraction.MLTasks; +using BotSharp.Abstraction.Models; using BotSharp.Abstraction.Templating; namespace BotSharp.Core.Conversations.Services; public partial class ConversationService { - public async Task GetConversationSummary(IEnumerable conversationIds) + public async Task GetConversationSummary(ConversationSummaryModel model) { - if (conversationIds.IsNullOrEmpty()) return string.Empty; + if (model.ConversationIds.IsNullOrEmpty()) return string.Empty; var routing = _services.GetRequiredService(); var agentService = _services.GetRequiredService(); var contents = new List(); - foreach ( var conversationId in conversationIds) + foreach (var conversationId in model.ConversationIds) { if (string.IsNullOrEmpty(conversationId)) continue; @@ -31,16 +32,16 @@ public async Task GetConversationSummary(IEnumerable conversatio if (contents.IsNullOrEmpty()) return string.Empty; - var router = await agentService.LoadAgent(AIAssistant); - var prompt = GetPrompt(router, contents); - var summary = await Summarize(router, prompt); + var agent = await agentService.LoadAgent(model.AgentId); + var prompt = GetPrompt(agent, model.TemplateName, contents); + var summary = await Summarize(agent, prompt); return summary; } - private string GetPrompt(Agent agent, List contents) + private string GetPrompt(Agent agent, string templateName, List contents) { - var template = agent.Templates.First(x => x.Name == "conversation.summary").Content; + var template = agent.Templates.First(x => x.Name == templateName).Content; var render = _services.GetRequiredService(); var texts = new List(); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index bcb92f740..d3da550ff 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -185,7 +185,7 @@ public async Task> GetDialogs([FromRoute] string public async Task GetConversationSummary([FromBody] ConversationSummaryModel input) { var service = _services.GetRequiredService(); - return await service.GetConversationSummary(input.ConversationIds); + return await service.GetConversationSummary(input); } [HttpPut("/conversation/{conversationId}/update-title")] diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Request/ConversationSummaryModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Request/ConversationSummaryModel.cs deleted file mode 100644 index 0854ab2af..000000000 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Request/ConversationSummaryModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Text.Json.Serialization; - -namespace BotSharp.OpenAPI.ViewModels.Conversations; - -public class ConversationSummaryModel -{ - [JsonPropertyName("conversation_ids")] - public List ConversationIds { get; set; } = new List(); -}