From c514bed096ba3ccef6712908571e3efdfc191f13 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 17 Jul 2024 14:28:29 -0500 Subject: [PATCH] add comments --- .../Files/IBotSharpFileService.cs | 15 ++++++++++++- .../Files/Models/MessageFileModel.cs | 9 ++++++++ .../BotSharpFileService.Conversation.cs | 21 ++++++++++++------- .../Functions/HandleEmailRequestFn.cs | 2 +- .../Functions/ReadImageFn.cs | 2 +- .../Functions/ReadPdfFn.cs | 2 +- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/IBotSharpFileService.cs b/src/Infrastructure/BotSharp.Abstraction/Files/IBotSharpFileService.cs index 65db27d3..3f0f0c5c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/IBotSharpFileService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/IBotSharpFileService.cs @@ -3,9 +3,22 @@ namespace BotSharp.Abstraction.Files; public interface IBotSharpFileService { string GetDirectory(string conversationId); - Task> GetChatImages(string conversationId, string source, + + /// + /// Get the files that have been uploaded in the chat. + /// If includeScreenShot is true, it will take the screenshots of non-image files, such as pdf, and return the screenshots instead of the original file. + /// + /// + /// + /// + /// + /// + /// + /// + Task> GetChatFiles(string conversationId, string source, IEnumerable conversations, IEnumerable contentTypes, bool includeScreenShot = false, int? offset = null); + IEnumerable GetMessageFiles(string conversationId, IEnumerable messageIds, string source, bool imageOnly = false); string GetMessageFile(string conversationId, string messageId, string source, string index, string fileName); IEnumerable GetMessagesWithFile(string conversationId, IEnumerable messageIds); diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Models/MessageFileModel.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Models/MessageFileModel.cs index 999f76de..7cd93269 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Files/Models/MessageFileModel.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Files/Models/MessageFileModel.cs @@ -5,12 +5,21 @@ public class MessageFileModel [JsonPropertyName("message_id")] public string MessageId { get; set; } + /// + /// External file url + /// [JsonPropertyName("file_url")] public string FileUrl { get; set; } + /// + /// Internal file storage url + /// [JsonPropertyName("file_storage_url")] public string FileStorageUrl { get; set; } + /// + /// File name without extension + /// [JsonPropertyName("file_name")] public string FileName { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Conversation.cs b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Conversation.cs index ff80690a..1b98f0d9 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Conversation.cs @@ -6,7 +6,7 @@ namespace BotSharp.Core.Files.Services; public partial class BotSharpFileService { - public async Task> GetChatImages(string conversationId, string source, + public async Task> GetChatFiles(string conversationId, string source, IEnumerable conversations, IEnumerable contentTypes, bool includeScreenShot = false, int? offset = null) { @@ -69,9 +69,7 @@ public partial class BotSharpFileService } var fileName = Path.GetFileNameWithoutExtension(file); - var extension = Path.GetExtension(file); - var fileType = extension.Substring(1); - + var fileType = Path.GetExtension(file).Substring(1); var model = new MessageFileModel() { MessageId = messageId, @@ -290,10 +288,13 @@ public partial class BotSharpFileService contentType = GetFileContentType(screenShot); if (!_imageTypes.Contains(contentType)) continue; + var fileName = Path.GetFileNameWithoutExtension(screenShot); + var fileType = Path.GetExtension(file).Substring(1); var model = new MessageFileModel() { MessageId = messageId, - FileName = Path.GetFileName(screenShot), + FileName = fileName, + FileType = fileType, FileStorageUrl = screenShot, ContentType = contentType, FileSource = source @@ -307,10 +308,13 @@ public partial class BotSharpFileService foreach (var image in images) { contentType = GetFileContentType(image); + var fileName = Path.GetFileNameWithoutExtension(image); + var fileType = Path.GetExtension(image).Substring(1); var model = new MessageFileModel() { MessageId = messageId, - FileName = Path.GetFileName(image), + FileName = fileName, + FileType = fileType, FileStorageUrl = image, ContentType = contentType, FileSource = source @@ -321,10 +325,13 @@ public partial class BotSharpFileService } else { + var fileName = Path.GetFileNameWithoutExtension(file); + var fileType = Path.GetExtension(file).Substring(1); var model = new MessageFileModel() { MessageId = messageId, - FileName = Path.GetFileName(file), + FileName = fileName, + FileType = fileType, FileStorageUrl = file, ContentType = contentType, FileSource = source diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs index 82c1010a..984732a9 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailRequestFn.cs @@ -110,7 +110,7 @@ public class HandleEmailRequestFn : IFunctionCallback }; var provider = llmProviderService.GetProviders().FirstOrDefault(x => x == "openai"); - var model = llmProviderService.GetProviderModel(provider: provider, id: "gpt-4", multiModal: true); + var model = llmProviderService.GetProviderModel(provider: provider, id: "gpt-4"); var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model.Name); var response = await completion.GetChatCompletions(agent, dialogs); var content = response?.Content ?? string.Empty; diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadImageFn.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadImageFn.cs index 9ae19250..66f69353 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadImageFn.cs @@ -52,7 +52,7 @@ public class ReadImageFn : IFunctionCallback } var fileService = _services.GetRequiredService(); - var images = await fileService.GetChatImages(conversationId, FileSourceType.User, dialogs, _imageContentTypes); + var images = await fileService.GetChatFiles(conversationId, FileSourceType.User, dialogs, _imageContentTypes); foreach (var dialog in dialogs) { diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadPdfFn.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadPdfFn.cs index 0464f186..85c2afbc 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadPdfFn.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/ReadPdfFn.cs @@ -51,7 +51,7 @@ public class ReadPdfFn : IFunctionCallback } var fileService = _services.GetRequiredService(); - var files = await fileService.GetChatImages(conversationId, FileSourceType.User, dialogs, _pdfContentTypes, includeScreenShot: true); + var files = await fileService.GetChatFiles(conversationId, FileSourceType.User, dialogs, _pdfContentTypes, includeScreenShot: true); foreach (var dialog in dialogs) {