Skip to content

Commit c9a1761

Browse files
author
Jicheng Lu
committed
change param name
1 parent 2a10294 commit c9a1761

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

src/Infrastructure/BotSharp.Abstraction/Files/IFileBasicService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public interface IFileBasicService
1111
/// </summary>
1212
/// <param name="conversationId"></param>
1313
/// <param name="source"></param>
14-
/// <param name="conversations"></param>
14+
/// <param name="dialogs"></param>
1515
/// <param name="contentTypes"></param>
1616
/// <param name="includeScreenShot"></param>
1717
/// <param name="offset"></param>
1818
/// <returns></returns>
1919
Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
20-
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes,
20+
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes,
2121
bool includeScreenShot = false, int? offset = null);
2222

2323
/// <summary>

src/Infrastructure/BotSharp.Abstraction/Files/IFileInstructService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public interface IFileInstructService
2222

2323
#region Select file
2424
Task<IEnumerable<MessageFileModel>> SelectMessageFiles(string conversationId,
25-
string? agentId = null, string? template = null, bool includeBotFile = false, bool fromBreakpoint = false,
25+
string? agentId = null, string? template = null, string? description = null,
26+
bool includeBotFile = false, bool fromBreakpoint = false,
2627
int? offset = null, IEnumerable<string>? contentTypes = null);
2728
#endregion
2829
}

src/Infrastructure/BotSharp.Core/Files/Services/Basic/FileBasicService.Conversation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ namespace BotSharp.Core.Files.Services;
77
public partial class FileBasicService
88
{
99
public async Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
10-
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes = null,
10+
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes = null,
1111
bool includeScreenShot = false, int? offset = null)
1212
{
1313
var files = new List<MessageFileModel>();
14-
if (string.IsNullOrEmpty(conversationId) || conversations.IsNullOrEmpty())
14+
if (string.IsNullOrEmpty(conversationId) || dialogs.IsNullOrEmpty())
1515
{
1616
return files;
1717
}
1818

19-
var messageIds = GetMessageIds(conversations, offset);
19+
var messageIds = GetMessageIds(dialogs, offset);
2020
var pathPrefix = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER);
2121

2222
foreach (var messageId in messageIds)
@@ -247,9 +247,9 @@ private string GetConversationFileDirectory(string? conversationId, string? mess
247247
return dir;
248248
}
249249

250-
private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> conversations, int? offset = null)
250+
private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs, int? offset = null)
251251
{
252-
if (conversations.IsNullOrEmpty()) return Enumerable.Empty<string>();
252+
if (dialogs.IsNullOrEmpty()) return Enumerable.Empty<string>();
253253

254254
if (offset.HasValue && offset < 1)
255255
{
@@ -259,11 +259,11 @@ private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> conversat
259259
var messageIds = new List<string>();
260260
if (offset.HasValue)
261261
{
262-
messageIds = conversations.Select(x => x.MessageId).Distinct().TakeLast(offset.Value).ToList();
262+
messageIds = dialogs.Select(x => x.MessageId).Distinct().TakeLast(offset.Value).ToList();
263263
}
264264
else
265265
{
266-
messageIds = conversations.Select(x => x.MessageId).Distinct().ToList();
266+
messageIds = dialogs.Select(x => x.MessageId).Distinct().ToList();
267267
}
268268

269269
return messageIds;

src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace BotSharp.Core.Files.Services;
66
public partial class FileInstructService
77
{
88
public async Task<IEnumerable<MessageFileModel>> SelectMessageFiles(string conversationId,
9-
string? agentId = null, string? template = null, bool includeBotFile = false, bool fromBreakpoint = false,
9+
string? agentId = null, string? template = null, string? description = null,
10+
bool includeBotFile = false, bool fromBreakpoint = false,
1011
int? offset = null, IEnumerable<string>? contentTypes = null)
1112
{
1213
if (string.IsNullOrEmpty(conversationId))
@@ -30,10 +31,11 @@ public async Task<IEnumerable<MessageFileModel>> SelectMessageFiles(string conve
3031
return Enumerable.Empty<MessageFileModel>();
3132
}
3233

33-
return await SelectFiles(agentId, template, files, dialogs);
34+
return await SelectFiles(agentId, template, description, files, dialogs);
3435
}
3536

36-
private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, string? template, IEnumerable<MessageFileModel> files, List<RoleDialogModel> dialogs)
37+
private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, string? template, string? description,
38+
IEnumerable<MessageFileModel> files, List<RoleDialogModel> dialogs)
3739
{
3840
if (files.IsNullOrEmpty()) return new List<MessageFileModel>();
3941

@@ -52,7 +54,7 @@ private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, s
5254
template = !string.IsNullOrWhiteSpace(template) ? template : "select_file_prompt";
5355

5456
var foundAgent = db.GetAgent(agentId);
55-
var prompt = db.GetAgentTemplate(agentId, template);
57+
var prompt = db.GetAgentTemplate(BuiltInAgentId.UtilityAssistant, template);
5658
prompt = render.Render(prompt, new Dictionary<string, object>
5759
{
5860
{ "file_list", promptFiles }
@@ -68,8 +70,14 @@ private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, s
6870
var provider = llmProviderService.GetProviders().FirstOrDefault(x => x == "openai");
6971
var model = llmProviderService.GetProviderModel(provider: provider, id: "gpt-4");
7072
var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model.Name);
71-
var latest = dialogs.Last();
72-
var response = await completion.GetChatCompletions(agent, new List<RoleDialogModel> { latest });
73+
74+
var message = dialogs.Last();
75+
if (!string.IsNullOrWhiteSpace(description))
76+
{
77+
message = RoleDialogModel.From(message, AgentRole.User, description);
78+
}
79+
80+
var response = await completion.GetChatCompletions(agent, new List<RoleDialogModel> { message });
7381
var content = response?.Content ?? string.Empty;
7482
var selecteds = JsonSerializer.Deserialize<FileSelectContext>(content);
7583
var fids = selecteds?.Selecteds ?? new List<int>();

src/Plugins/BotSharp.Plugin.FileHandler/Functions/EditImageFn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void SetImageOptions()
5151
private async Task<MessageFileModel?> SelectImage(string? description)
5252
{
5353
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
54-
var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, contentTypes: new List<string> { MediaTypeNames.Image.Png });
54+
var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, description: description, contentTypes: new List<string> { MediaTypeNames.Image.Png });
5555
return selecteds?.FirstOrDefault();
5656
}
5757

src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.Conversation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ namespace BotSharp.Plugin.TencentCos.Services;
88
public partial class TencentCosService
99
{
1010
public async Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
11-
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes = null,
11+
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes = null,
1212
bool includeScreenShot = false, int? offset = null)
1313
{
1414
var files = new List<MessageFileModel>();
15-
if (string.IsNullOrEmpty(conversationId) || conversations.IsNullOrEmpty())
15+
if (string.IsNullOrEmpty(conversationId) || dialogs.IsNullOrEmpty())
1616
{
1717
return files;
1818
}
1919

20-
var messageIds = GetMessageIds(conversations, offset);
20+
var messageIds = GetMessageIds(dialogs, offset);
2121
var pathPrefix = $"{CONVERSATION_FOLDER}/{conversationId}/{FILE_FOLDER}";
2222

2323
foreach (var messageId in messageIds)

0 commit comments

Comments
 (0)