diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/IFileBasicService.cs b/src/Infrastructure/BotSharp.Abstraction/Files/IFileBasicService.cs
index d8baf6e7..b0e5d261 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Files/IFileBasicService.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Files/IFileBasicService.cs
@@ -11,13 +11,13 @@ public interface IFileBasicService
///
///
///
- ///
+ ///
///
///
///
///
Task> GetChatFiles(string conversationId, string source,
- IEnumerable conversations, IEnumerable? contentTypes,
+ IEnumerable dialogs, IEnumerable? contentTypes,
bool includeScreenShot = false, int? offset = null);
///
diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/IFileInstructService.cs b/src/Infrastructure/BotSharp.Abstraction/Files/IFileInstructService.cs
index 7d717fd0..433a582f 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Files/IFileInstructService.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Files/IFileInstructService.cs
@@ -22,7 +22,8 @@ public interface IFileInstructService
#region Select file
Task> SelectMessageFiles(string conversationId,
- string? agentId = null, string? template = null, bool includeBotFile = false, bool fromBreakpoint = false,
+ string? agentId = null, string? template = null, string? description = null,
+ bool includeBotFile = false, bool fromBreakpoint = false,
int? offset = null, IEnumerable? contentTypes = null);
#endregion
}
diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Basic/FileBasicService.Conversation.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Basic/FileBasicService.Conversation.cs
index fa5df123..403e2da5 100644
--- a/src/Infrastructure/BotSharp.Core/Files/Services/Basic/FileBasicService.Conversation.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/Services/Basic/FileBasicService.Conversation.cs
@@ -7,16 +7,16 @@ namespace BotSharp.Core.Files.Services;
public partial class FileBasicService
{
public async Task> GetChatFiles(string conversationId, string source,
- IEnumerable conversations, IEnumerable? contentTypes = null,
+ IEnumerable dialogs, IEnumerable? contentTypes = null,
bool includeScreenShot = false, int? offset = null)
{
var files = new List();
- if (string.IsNullOrEmpty(conversationId) || conversations.IsNullOrEmpty())
+ if (string.IsNullOrEmpty(conversationId) || dialogs.IsNullOrEmpty())
{
return files;
}
- var messageIds = GetMessageIds(conversations, offset);
+ var messageIds = GetMessageIds(dialogs, offset);
var pathPrefix = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER);
foreach (var messageId in messageIds)
@@ -247,9 +247,9 @@ public partial class FileBasicService
return dir;
}
- private IEnumerable GetMessageIds(IEnumerable conversations, int? offset = null)
+ private IEnumerable GetMessageIds(IEnumerable dialogs, int? offset = null)
{
- if (conversations.IsNullOrEmpty()) return Enumerable.Empty();
+ if (dialogs.IsNullOrEmpty()) return Enumerable.Empty();
if (offset.HasValue && offset < 1)
{
@@ -259,11 +259,11 @@ public partial class FileBasicService
var messageIds = new List();
if (offset.HasValue)
{
- messageIds = conversations.Select(x => x.MessageId).Distinct().TakeLast(offset.Value).ToList();
+ messageIds = dialogs.Select(x => x.MessageId).Distinct().TakeLast(offset.Value).ToList();
}
else
{
- messageIds = conversations.Select(x => x.MessageId).Distinct().ToList();
+ messageIds = dialogs.Select(x => x.MessageId).Distinct().ToList();
}
return messageIds;
diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
index e4602b9f..dfed9f77 100644
--- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
@@ -6,7 +6,8 @@ namespace BotSharp.Core.Files.Services;
public partial class FileInstructService
{
public async Task> SelectMessageFiles(string conversationId,
- string? agentId = null, string? template = null, bool includeBotFile = false, bool fromBreakpoint = false,
+ string? agentId = null, string? template = null, string? description = null,
+ bool includeBotFile = false, bool fromBreakpoint = false,
int? offset = null, IEnumerable? contentTypes = null)
{
if (string.IsNullOrEmpty(conversationId))
@@ -30,10 +31,11 @@ public partial class FileInstructService
return Enumerable.Empty();
}
- return await SelectFiles(agentId, template, files, dialogs);
+ return await SelectFiles(agentId, template, description, files, dialogs);
}
- private async Task> SelectFiles(string? agentId, string? template, IEnumerable files, List dialogs)
+ private async Task> SelectFiles(string? agentId, string? template, string? description,
+ IEnumerable files, List dialogs)
{
if (files.IsNullOrEmpty()) return new List();
@@ -52,7 +54,7 @@ public partial class FileInstructService
template = !string.IsNullOrWhiteSpace(template) ? template : "select_file_prompt";
var foundAgent = db.GetAgent(agentId);
- var prompt = db.GetAgentTemplate(agentId, template);
+ var prompt = db.GetAgentTemplate(BuiltInAgentId.UtilityAssistant, template);
prompt = render.Render(prompt, new Dictionary
{
{ "file_list", promptFiles }
@@ -68,8 +70,14 @@ public partial class FileInstructService
var provider = llmProviderService.GetProviders().FirstOrDefault(x => x == "openai");
var model = llmProviderService.GetProviderModel(provider: provider, id: "gpt-4");
var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model.Name);
- var latest = dialogs.Last();
- var response = await completion.GetChatCompletions(agent, new List { latest });
+
+ var message = dialogs.Last();
+ if (!string.IsNullOrWhiteSpace(description))
+ {
+ message = RoleDialogModel.From(message, AgentRole.User, description);
+ }
+
+ var response = await completion.GetChatCompletions(agent, new List { message });
var content = response?.Content ?? string.Empty;
var selecteds = JsonSerializer.Deserialize(content);
var fids = selecteds?.Selecteds ?? new List();
diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/EditImageFn.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/EditImageFn.cs
index 52cb1249..e9d1851b 100644
--- a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/EditImageFn.cs
+++ b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/EditImageFn.cs
@@ -51,7 +51,7 @@ public class EditImageFn : IFunctionCallback
private async Task SelectImage(string? description)
{
var fileInstruct = _services.GetRequiredService();
- var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, contentTypes: new List { MediaTypeNames.Image.Png });
+ var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, description: description, contentTypes: new List { MediaTypeNames.Image.Png });
return selecteds?.FirstOrDefault();
}
diff --git a/src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.Conversation.cs b/src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.Conversation.cs
index ac661509..d67d69f0 100644
--- a/src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.Conversation.cs
+++ b/src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.Conversation.cs
@@ -8,16 +8,16 @@ namespace BotSharp.Plugin.TencentCos.Services;
public partial class TencentCosService
{
public async Task> GetChatFiles(string conversationId, string source,
- IEnumerable conversations, IEnumerable? contentTypes = null,
+ IEnumerable dialogs, IEnumerable? contentTypes = null,
bool includeScreenShot = false, int? offset = null)
{
var files = new List();
- if (string.IsNullOrEmpty(conversationId) || conversations.IsNullOrEmpty())
+ if (string.IsNullOrEmpty(conversationId) || dialogs.IsNullOrEmpty())
{
return files;
}
- var messageIds = GetMessageIds(conversations, offset);
+ var messageIds = GetMessageIds(dialogs, offset);
var pathPrefix = $"{CONVERSATION_FOLDER}/{conversationId}/{FILE_FOLDER}";
foreach (var messageId in messageIds)