diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs index 9df6ae7f..18cee8fc 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs @@ -53,4 +53,6 @@ public interface IConversationService /// Append user init words /// Task UpdateBreakpoint(bool resetStates = false, string? reason = null); + + Task GetConversationSummary(string conversationId); } diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 0ddc52e8..10e21b3c 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -56,6 +56,7 @@ + @@ -142,6 +143,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs new file mode 100644 index 00000000..53c6470a --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs @@ -0,0 +1,32 @@ +using BotSharp.Abstraction.Infrastructures.Enums; +using BotSharp.Abstraction.Templating; + +namespace BotSharp.Core.Conversations.Services; + +public partial class ConversationService +{ + public async Task GetConversationSummary(string conversationId) + { + if (string.IsNullOrEmpty(conversationId)) return string.Empty; + + var dialogs = _storage.GetDialogs(conversationId); + + return string.Empty; + } + + private IEnumerable BuildConversationContent(List dialogs) + { + + } + + private string GetPrompt(Agent router, List dialogs) + { + var template = router.Templates.First(x => x.Name == "conversation.summary").Content; + + var render = _services.GetRequiredService(); + return render.Render(template, new Dictionary + { + { "conversation", } + }); + } +} diff --git a/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/conversation.summary.liquid b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/conversation.summary.liquid new file mode 100644 index 00000000..3b6bb53f --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/conversation.summary.liquid @@ -0,0 +1,6 @@ +Please follow these steps to summarize the conversation: +1. Read the [CONVERSATION] content. +2. Summarize the conversation in one sentence. + +[CONVERSATION] +{{ conversation }} \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index fd66b225..ef44472a 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -134,6 +134,13 @@ public class ConversationController : ControllerBase return result; } + [HttpGet("/conversation/{conversationId}/summary")] + public async Task GetConversationSummary([FromRoute] string conversationId) + { + var service = _services.GetRequiredService(); + return await service.GetConversationSummary(conversationId); + } + [HttpGet("/conversation/{conversationId}/user")] public async Task GetConversationUser([FromRoute] string conversationId) {