Skip to content

Commit a20eacb

Browse files
author
Jicheng Lu
committed
add dialog order and conversation thumbnail
1 parent 90392d0 commit a20eacb

20 files changed

Lines changed: 383 additions & 26 deletions

File tree

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

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

43
namespace BotSharp.Abstraction.Conversations;
54

@@ -41,7 +40,7 @@ Task<bool> SendMessage(string agentId,
4140
PostbackMessageModel? replyMessage,
4241
Func<RoleDialogModel, Task> onResponseReceived);
4342

44-
Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null);
43+
Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null, ConversationDialogFilter? filter = null);
4544
Task CleanHistory(string agentId);
4645

4746
/// <summary>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
using BotSharp.Abstraction.Repositories.Filters;
2+
13
namespace BotSharp.Abstraction.Conversations;
24

35
public interface IConversationStorage
46
{
57
Task Append(string conversationId, RoleDialogModel dialog);
68
Task Append(string conversationId, IEnumerable<RoleDialogModel> dialogs);
7-
Task<List<RoleDialogModel>> GetDialogs(string conversationId);
9+
Task<List<RoleDialogModel>> GetDialogs(string conversationId, ConversationDialogFilter? filter = null);
810
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace BotSharp.Abstraction.Conversations.Models;
2+
3+
public class ConversationFile
4+
{
5+
public string ConversationId { get; set; }
6+
public string? Thumbnail { get; set; }
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Repositories.Filters;
2+
3+
public class ConversationDialogFilter
4+
{
5+
public string Order { get; set; } = "asc";
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Repositories.Filters;
2+
3+
public class ConversationFileFilter
4+
{
5+
public IEnumerable<string> ConversationIds { get; set; } = [];
6+
}

src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ConversationFilter
3131
public List<string>? Tags { get; set; }
3232

3333
public bool IsLoadLatestStates { get; set; }
34+
public bool IsLoadThumbnail { get; set; }
3435

3536
public static ConversationFilter Empty()
3637
{

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Task CreateNewConversation(Conversation conversation)
129129
=> throw new NotImplementedException();
130130
Task<bool> DeleteConversations(IEnumerable<string> conversationIds)
131131
=> throw new NotImplementedException();
132-
Task<List<DialogElement>> GetConversationDialogs(string conversationId)
132+
Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null)
133133
=> throw new NotImplementedException();
134134
Task AppendConversationDialogs(string conversationId, List<DialogElement> dialogs)
135135
=> throw new NotImplementedException();
@@ -169,6 +169,12 @@ Task<List<string>> GetConversationsToMigrate(int batchSize = 100)
169169
=> throw new NotImplementedException();
170170
Task<bool> MigrateConvsersationLatestStates(string conversationId)
171171
=> throw new NotImplementedException();
172+
Task<List<ConversationFile>> GetConversationFiles(ConversationFileFilter filter)
173+
=> throw new NotImplementedException();
174+
Task<bool> SaveConversationFiles(List<ConversationFile> files)
175+
=> throw new NotImplementedException();
176+
Task<bool> DeleteConversationFiles(List<string> conversationIds)
177+
=> throw new NotImplementedException();
172178
#endregion
173179

174180
#region LLM Completion Log

src/Infrastructure/BotSharp.Abstraction/SideCar/IConversationSideCar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Repositories.Filters;
12
using BotSharp.Abstraction.SideCar.Options;
23

34
namespace BotSharp.Abstraction.SideCar;
@@ -8,7 +9,7 @@ public interface IConversationSideCar
89
bool IsEnabled { get; }
910

1011
Task AppendConversationDialogs(string conversationId, List<DialogElement> messages);
11-
Task<List<DialogElement>> GetConversationDialogs(string conversationId);
12+
Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null);
1213
Task UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint);
1314
Task<ConversationBreakpoint?> GetConversationBreakpoint(string conversationId);
1415
Task UpdateConversationStates(string conversationId, List<StateKeyValue> states);

src/Infrastructure/BotSharp.Core.SideCar/Services/BotSharpConversationSideCar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You may obtain a copy of the License at
1414
limitations under the License.
1515
******************************************************************************/
1616

17+
using BotSharp.Abstraction.Repositories.Filters;
1718
using BotSharp.Abstraction.SideCar.Options;
1819
using BotSharp.Core.Infrastructures;
1920

@@ -54,7 +55,7 @@ public async Task AppendConversationDialogs(string conversationId, List<DialogEl
5455
await Task.CompletedTask;
5556
}
5657

57-
public async Task<List<DialogElement>> GetConversationDialogs(string conversationId)
58+
public async Task<List<DialogElement>> GetConversationDialogs(string conversationId, ConversationDialogFilter? filter = null)
5859
{
5960
if (!IsValid(conversationId))
6061
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ public Task CleanHistory(string agentId)
154154
throw new NotImplementedException();
155155
}
156156

157-
public async Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null)
157+
public async Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null, ConversationDialogFilter? filter = null)
158158
{
159159
if (string.IsNullOrEmpty(_conversationId))
160160
{
161161
throw new ArgumentNullException("ConversationId is null.");
162162
}
163163

164-
var dialogs = await _storage.GetDialogs(_conversationId);
164+
var dialogs = await _storage.GetDialogs(_conversationId, filter);
165165

166166
if (!includeMessageTypes.IsNullOrEmpty())
167167
{
@@ -190,7 +190,7 @@ public async Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, b
190190
var agentMsgCount = await GetAgentMessageCount();
191191
var count = agentMsgCount.HasValue && agentMsgCount.Value > 0 ? agentMsgCount.Value : lastCount;
192192

193-
return dialogs.TakeLast(count).ToList();
193+
return filter?.Order == "desc" ? dialogs.Take(count).ToList() : dialogs.TakeLast(count).ToList();
194194
}
195195

196196
public async Task SetConversationId(string conversationId, List<MessageState> states, bool isReadOnly = false)

0 commit comments

Comments
 (0)