Skip to content

Commit 31bdd8f

Browse files
authored
Merge pull request #1070 from yileicn/master
optimize summary
2 parents c8149b6 + 5bfb8f8 commit 31bdd8f

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Abstraction.Loggers.Models;
21
using BotSharp.Abstraction.Repositories.Filters;
32

43
namespace BotSharp.Abstraction.Conversations;
@@ -53,7 +52,7 @@ Task<bool> SendMessage(string agentId,
5352
/// <returns></returns>
5453
Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates);
5554

56-
Task<string> GetConversationSummary(IEnumerable<string> conversationId);
55+
Task<string> GetConversationSummary(ConversationSummaryModel model);
5756

5857
Task<Conversation> GetConversationRecordOrCreateNew(string agentId);
5958

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace BotSharp.Abstraction.Models;
4+
5+
public class ConversationSummaryModel
6+
{
7+
[JsonPropertyName("conversation_ids")]
8+
public IEnumerable<string> ConversationIds { get; set; } = new List<string>();
9+
10+
private string _agentId;
11+
12+
[JsonPropertyName("agent_id")]
13+
public string AgentId
14+
{
15+
get => _agentId ?? BuiltInAgentId.AIAssistant;
16+
set => _agentId = value;
17+
}
18+
19+
private string _templateName;
20+
21+
[JsonPropertyName("template_name")]
22+
public string TemplateName
23+
{
24+
get => _templateName ?? "conversation.summary";
25+
set => _templateName = value;
26+
}
27+
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
using BotSharp.Abstraction.Conversations.Enums;
22
using BotSharp.Abstraction.MLTasks;
3+
using BotSharp.Abstraction.Models;
34
using BotSharp.Abstraction.Templating;
45

56
namespace BotSharp.Core.Conversations.Services;
67

78
public partial class ConversationService
89
{
9-
public async Task<string> GetConversationSummary(IEnumerable<string> conversationIds)
10+
public async Task<string> GetConversationSummary(ConversationSummaryModel model)
1011
{
11-
if (conversationIds.IsNullOrEmpty()) return string.Empty;
12+
if (model.ConversationIds.IsNullOrEmpty()) return string.Empty;
1213

1314
var routing = _services.GetRequiredService<IRoutingService>();
1415
var agentService = _services.GetRequiredService<IAgentService>();
1516

1617
var contents = new List<string>();
17-
foreach ( var conversationId in conversationIds)
18+
foreach (var conversationId in model.ConversationIds)
1819
{
1920
if (string.IsNullOrEmpty(conversationId)) continue;
2021

@@ -31,16 +32,16 @@ public async Task<string> GetConversationSummary(IEnumerable<string> conversatio
3132

3233
if (contents.IsNullOrEmpty()) return string.Empty;
3334

34-
var router = await agentService.LoadAgent(AIAssistant);
35-
var prompt = GetPrompt(router, contents);
36-
var summary = await Summarize(router, prompt);
35+
var agent = await agentService.LoadAgent(model.AgentId);
36+
var prompt = GetPrompt(agent, model.TemplateName, contents);
37+
var summary = await Summarize(agent, prompt);
3738

3839
return summary;
3940
}
4041

41-
private string GetPrompt(Agent agent, List<string> contents)
42+
private string GetPrompt(Agent agent, string templateName, List<string> contents)
4243
{
43-
var template = agent.Templates.First(x => x.Name == "conversation.summary").Content;
44+
var template = agent.Templates.First(x => x.Name == templateName).Content;
4445
var render = _services.GetRequiredService<ITemplateRender>();
4546

4647
var texts = new List<string>();

src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public async Task<IEnumerable<ChatResponseModel>> GetDialogs([FromRoute] string
185185
public async Task<string> GetConversationSummary([FromBody] ConversationSummaryModel input)
186186
{
187187
var service = _services.GetRequiredService<IConversationService>();
188-
return await service.GetConversationSummary(input.ConversationIds);
188+
return await service.GetConversationSummary(input);
189189
}
190190

191191
[HttpPut("/conversation/{conversationId}/update-title")]

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Conversations/Request/ConversationSummaryModel.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)