From aecff925b16322d02cb67d7a1641288542799da8 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Thu, 18 Jul 2024 13:20:38 -0500 Subject: [PATCH] add error msg --- .../BotSharp.Core/Files/Services/BotSharpFileService.Pdf.cs | 6 +++--- .../Files/Services/BotSharpFileService.User.cs | 2 +- .../BotSharp.OpenAPI/Controllers/InstructModeController.cs | 3 +-- .../Functions/GenerateImageFn.cs | 6 +++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Pdf.cs b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Pdf.cs index 2a00938d..784b4173 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Pdf.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.Pdf.cs @@ -44,7 +44,7 @@ public partial class BotSharpFileService } catch (Exception ex) { - _logger.LogError($"Error when analyzing pdf in file service: {ex.Message}"); + _logger.LogError($"Error when analyzing pdf in file service: {ex.Message}\r\n{ex.InnerException}"); return content; } finally @@ -105,7 +105,7 @@ public partial class BotSharpFileService } catch (Exception ex) { - _logger.LogWarning($"Error when saving pdf file: {ex.Message}"); + _logger.LogWarning($"Error when saving pdf file: {ex.Message}\r\n{ex.InnerException}"); continue; } } @@ -133,7 +133,7 @@ public partial class BotSharpFileService } catch (Exception ex) { - _logger.LogWarning($"Error when converting pdf file to images ({file}): {ex.Message}"); + _logger.LogWarning($"Error when converting pdf file to images ({file}): {ex.Message}\r\n{ex.InnerException}"); continue; } } diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.User.cs b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.User.cs index 717b4874..fa99b13f 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.User.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/BotSharpFileService.User.cs @@ -40,7 +40,7 @@ public partial class BotSharpFileService } catch (Exception ex) { - _logger.LogWarning($"Error when saving user avatar: {ex.Message}"); + _logger.LogWarning($"Error when saving user avatar: {ex.Message}\r\n{ex.InnerException}"); return false; } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs index f2d4bf5d..a19eb6df 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs @@ -115,8 +115,7 @@ public class InstructModeController : ControllerBase try { - var completion = CompletionProvider.GetImageGeneration(_services, provider: input.Provider ?? "openai", - model: input.Model ?? "dall-e-3", imageGenerate: true); + var completion = CompletionProvider.GetImageGeneration(_services, provider: input.Provider ?? "openai", model: input.Model ?? "dall-e-3"); var message = await completion.GetImageGeneration(new Agent() { Id = Guid.Empty.ToString(), diff --git a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/GenerateImageFn.cs b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/GenerateImageFn.cs index 8f24e98d..50482e66 100644 --- a/src/Plugins/BotSharp.Plugin.FileHandler/Functions/GenerateImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.FileHandler/Functions/GenerateImageFn.cs @@ -59,7 +59,7 @@ public class GenerateImageFn : IFunctionCallback { try { - var completion = CompletionProvider.GetImageGeneration(_services, provider: "openai", model: "dall-e-3", imageGenerate: true); + var completion = CompletionProvider.GetImageGeneration(_services, provider: "openai", model: "dall-e-3"); var text = !string.IsNullOrWhiteSpace(description) ? description : message.Content; var dialog = RoleDialogModel.From(message, AgentRole.User, text); var result = await completion.GetImageGeneration(agent, new List { dialog }); @@ -69,7 +69,7 @@ public class GenerateImageFn : IFunctionCallback catch (Exception ex) { var error = $"Error when generating image."; - _logger.LogWarning($"{error} {ex.Message}"); + _logger.LogWarning($"{error} {ex.Message}\r\n{ex.InnerException}"); return error; } } @@ -81,7 +81,7 @@ public class GenerateImageFn : IFunctionCallback var files = images.Where(x => !string.IsNullOrEmpty(x?.ImageData)).Select(x => new BotSharpFile { FileName = $"{Guid.NewGuid()}.png", - FileData = $"data:image/png;base64,{x.ImageData}" + FileData = $"data:{MediaTypeNames.Image.Png};base64,{x.ImageData}" }).ToList(); var fileService = _services.GetRequiredService();