merge message files
This commit is contained in:
parent
3b606974f0
commit
5eb241d26b
|
|
@ -20,7 +20,7 @@ public partial class FileInstructService
|
|||
if (options.IncludeBotFile)
|
||||
{
|
||||
var botFiles = _fileStorage.GetMessageFiles(conversationId, messageIds, FileSourceType.Bot, options.ContentTypes);
|
||||
files = files.Concat(botFiles);
|
||||
files = MergeMessageFiles(messageIds, files, botFiles);
|
||||
}
|
||||
|
||||
if (files.IsNullOrEmpty())
|
||||
|
|
@ -31,6 +31,24 @@ public partial class FileInstructService
|
|||
return await SelectFiles(files, dialogs, options);
|
||||
}
|
||||
|
||||
private IEnumerable<MessageFileModel> MergeMessageFiles(IEnumerable<string> messageIds, IEnumerable<MessageFileModel> userFiles, IEnumerable<MessageFileModel> botFiles)
|
||||
{
|
||||
var files = new List<MessageFileModel>();
|
||||
|
||||
if (messageIds.IsNullOrEmpty()) return files;
|
||||
|
||||
foreach (var messageId in messageIds)
|
||||
{
|
||||
var users = userFiles.Where(x => x.MessageId == messageId).ToList();
|
||||
var bots = botFiles.Where(x => x.MessageId == messageId).ToList();
|
||||
|
||||
if (!users.IsNullOrEmpty()) files.AddRange(users);
|
||||
if (!bots.IsNullOrEmpty()) files.AddRange(bots);
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<MessageFileModel>> SelectFiles(IEnumerable<MessageFileModel> files, IEnumerable<RoleDialogModel> dialogs, SelectFileOptions options)
|
||||
{
|
||||
if (files.IsNullOrEmpty()) return new List<MessageFileModel>();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class ReadImageFn : IFunctionCallback
|
|||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
|
||||
var wholeDialogs = conv.GetDialogHistory();
|
||||
var dialogs = await AssembleFiles(conv.ConversationId, wholeDialogs);
|
||||
var dialogs = AssembleFiles(conv.ConversationId, wholeDialogs);
|
||||
var agent = await agentService.LoadAgent(BuiltInAgentId.UtilityAssistant);
|
||||
var fileAgent = new Agent
|
||||
{
|
||||
|
|
@ -38,7 +38,7 @@ public class ReadImageFn : IFunctionCallback
|
|||
return true;
|
||||
}
|
||||
|
||||
private async Task<List<RoleDialogModel>> AssembleFiles(string conversationId, List<RoleDialogModel> dialogs)
|
||||
private List<RoleDialogModel> AssembleFiles(string conversationId, List<RoleDialogModel> dialogs)
|
||||
{
|
||||
if (dialogs.IsNullOrEmpty())
|
||||
{
|
||||
|
|
@ -46,8 +46,6 @@ public class ReadImageFn : IFunctionCallback
|
|||
}
|
||||
|
||||
var fileStorage = _services.GetRequiredService<IFileStorageService>();
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
|
||||
var messageIds = dialogs.Select(x => x.MessageId).Distinct().ToList();
|
||||
var images = fileStorage.GetMessageFiles(conversationId, messageIds, FileSourceType.User, new List<string>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ public class ReadPdfFn : IFunctionCallback
|
|||
}
|
||||
|
||||
var fileStorage = _services.GetRequiredService<IFileStorageService>();
|
||||
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
|
||||
|
||||
var messageIds = dialogs.Select(x => x.MessageId).Distinct().ToList();
|
||||
var screenshots = await fileStorage.GetMessageFileScreenshots(conversationId, messageIds);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue