change param name

This commit is contained in:
Jicheng Lu 2024-08-07 17:53:58 -05:00
parent 2a10294d70
commit c9a1761228
6 changed files with 29 additions and 20 deletions

View file

@ -11,13 +11,13 @@ public interface IFileBasicService
/// </summary>
/// <param name="conversationId"></param>
/// <param name="source"></param>
/// <param name="conversations"></param>
/// <param name="dialogs"></param>
/// <param name="contentTypes"></param>
/// <param name="includeScreenShot"></param>
/// <param name="offset"></param>
/// <returns></returns>
Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes,
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes,
bool includeScreenShot = false, int? offset = null);
/// <summary>

View file

@ -22,7 +22,8 @@ public interface IFileInstructService
#region Select file
Task<IEnumerable<MessageFileModel>> 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<string>? contentTypes = null);
#endregion
}

View file

@ -7,16 +7,16 @@ namespace BotSharp.Core.Files.Services;
public partial class FileBasicService
{
public async Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes = null,
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes = null,
bool includeScreenShot = false, int? offset = null)
{
var files = new List<MessageFileModel>();
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<string> GetMessageIds(IEnumerable<RoleDialogModel> conversations, int? offset = null)
private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs, int? offset = null)
{
if (conversations.IsNullOrEmpty()) return Enumerable.Empty<string>();
if (dialogs.IsNullOrEmpty()) return Enumerable.Empty<string>();
if (offset.HasValue && offset < 1)
{
@ -259,11 +259,11 @@ public partial class FileBasicService
var messageIds = new List<string>();
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;

View file

@ -6,7 +6,8 @@ namespace BotSharp.Core.Files.Services;
public partial class FileInstructService
{
public async Task<IEnumerable<MessageFileModel>> 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<string>? contentTypes = null)
{
if (string.IsNullOrEmpty(conversationId))
@ -30,10 +31,11 @@ public partial class FileInstructService
return Enumerable.Empty<MessageFileModel>();
}
return await SelectFiles(agentId, template, files, dialogs);
return await SelectFiles(agentId, template, description, files, dialogs);
}
private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, string? template, IEnumerable<MessageFileModel> files, List<RoleDialogModel> dialogs)
private async Task<IEnumerable<MessageFileModel>> SelectFiles(string? agentId, string? template, string? description,
IEnumerable<MessageFileModel> files, List<RoleDialogModel> dialogs)
{
if (files.IsNullOrEmpty()) return new List<MessageFileModel>();
@ -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<string, object>
{
{ "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<RoleDialogModel> { latest });
var message = dialogs.Last();
if (!string.IsNullOrWhiteSpace(description))
{
message = RoleDialogModel.From(message, AgentRole.User, description);
}
var response = await completion.GetChatCompletions(agent, new List<RoleDialogModel> { message });
var content = response?.Content ?? string.Empty;
var selecteds = JsonSerializer.Deserialize<FileSelectContext>(content);
var fids = selecteds?.Selecteds ?? new List<int>();

View file

@ -51,7 +51,7 @@ public class EditImageFn : IFunctionCallback
private async Task<MessageFileModel?> SelectImage(string? description)
{
var fileInstruct = _services.GetRequiredService<IFileInstructService>();
var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, contentTypes: new List<string> { MediaTypeNames.Image.Png });
var selecteds = await fileInstruct.SelectMessageFiles(_conversationId, description: description, contentTypes: new List<string> { MediaTypeNames.Image.Png });
return selecteds?.FirstOrDefault();
}

View file

@ -8,16 +8,16 @@ namespace BotSharp.Plugin.TencentCos.Services;
public partial class TencentCosService
{
public async Task<IEnumerable<MessageFileModel>> GetChatFiles(string conversationId, string source,
IEnumerable<RoleDialogModel> conversations, IEnumerable<string>? contentTypes = null,
IEnumerable<RoleDialogModel> dialogs, IEnumerable<string>? contentTypes = null,
bool includeScreenShot = false, int? offset = null)
{
var files = new List<MessageFileModel>();
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)