From c84410b8234b8ab487007ba948cea0d4f858a224 Mon Sep 17 00:00:00 2001
From: Jicheng Lu <103353@smsassist.com>
Date: Mon, 31 Mar 2025 21:21:45 -0500
Subject: [PATCH] fix file selection
---
.../Files/Models/SelectFileOptions.cs | 4 ++--
.../Instruct/FileInstructService.Image.cs | 19 ++++++-------------
.../FileInstructService.SelectFile.cs | 5 ++---
.../Controllers/InstructModeController.cs | 8 +++-----
.../Image/ImageCompletionProvider.Edit.cs | 1 -
5 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/src/Infrastructure/BotSharp.Abstraction/Files/Models/SelectFileOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Files/Models/SelectFileOptions.cs
index d61c1b7c..29a1c9ea 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Files/Models/SelectFileOptions.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Files/Models/SelectFileOptions.cs
@@ -8,9 +8,9 @@ public class SelectFileOptions
public string? Provider { get; set; }
///
- /// Llm model id
+ /// Llm model
///
- public string? ModelId { get; set; }
+ public string? Model { get; set; }
///
/// Agent id
diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs
index 2f70bd22..845cdc2d 100644
--- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs
@@ -57,7 +57,7 @@ public partial class FileInstructService
{
Id = innerAgentId,
Instruction = instruction
- }, new RoleDialogModel(AgentRole.User, text));
+ }, new RoleDialogModel(AgentRole.User, instruction ?? text));
var hooks = _services.GetServices();
foreach (var hook in hooks)
@@ -90,8 +90,6 @@ public partial class FileInstructService
}
var innerAgentId = options?.AgentId ?? Guid.Empty.ToString();
- var instruction = await GetAgentTemplate(innerAgentId, options?.TemplateName);
-
var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "dall-e-2");
var bytes = await DownloadFile(image);
using var stream = new MemoryStream();
@@ -101,8 +99,7 @@ public partial class FileInstructService
var fileName = $"{image.FileName ?? "image"}.{image.FileExtension ?? "png"}";
var message = await completion.GetImageVariation(new Agent()
{
- Id = innerAgentId,
- Instruction = instruction
+ Id = innerAgentId
}, new RoleDialogModel(AgentRole.User, string.Empty), stream, fileName);
stream.Close();
@@ -120,9 +117,7 @@ public partial class FileInstructService
AgentId = innerAgentId,
Provider = completion.Provider,
Model = completion.Model,
- TemplateName = options?.TemplateName,
UserMessage = string.Empty,
- SystemInstruction = instruction,
CompletionText = message.Content
});
}
@@ -149,9 +144,8 @@ public partial class FileInstructService
var fileName = $"{image.FileName ?? "image"}.{image.FileExtension ?? "png"}";
var message = await completion.GetImageEdits(new Agent()
{
- Id = innerAgentId,
- Instruction = instruction
- }, new RoleDialogModel(AgentRole.User, text), stream, fileName);
+ Id = innerAgentId
+ }, new RoleDialogModel(AgentRole.User, instruction ?? text), stream, fileName);
stream.Close();
@@ -205,9 +199,8 @@ public partial class FileInstructService
var maskName = $"{mask.FileName ?? "mask"}.{mask.FileExtension ?? "png"}";
var message = await completion.GetImageEdits(new Agent()
{
- Id = innerAgentId,
- Instruction = instruction
- }, new RoleDialogModel(AgentRole.User, text), imageStream, imageName, maskStream, maskName);
+ Id = innerAgentId
+ }, new RoleDialogModel(AgentRole.User, instruction ?? text), imageStream, imageName, maskStream, maskName);
imageStream.Close();
maskStream.Close();
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 0e049b20..c789e069 100644
--- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
+++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.SelectFile.cs
@@ -93,10 +93,9 @@ public partial class FileInstructService
}
var providerName = options.Provider ?? "openai";
- var modelId = options?.ModelId ?? "gpt-4o";
+ var model = options?.Model ?? "gpt-4o-mini";
var provider = llmProviderService.GetProviders().FirstOrDefault(x => x == providerName);
- var model = llmProviderService.GetProviderModel(provider: provider, id: modelId);
- var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model.Name);
+ var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model);
var response = await completion.GetChatCompletions(agent, new List { message });
var content = response?.Content ?? string.Empty;
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs
index 55837f8d..abf3c6e3 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs
@@ -242,8 +242,7 @@ public class InstructModeController : ControllerBase
{
Provider = input.Provider,
Model = input.Model,
- AgentId = input.AgentId,
- TemplateName = input.TemplateName
+ AgentId = input.AgentId
});
imageViewModel.Content = message.Content;
imageViewModel.Images = message.GeneratedImages.Select(x => ImageViewModel.ToViewModel(x)).ToList();
@@ -262,7 +261,7 @@ public class InstructModeController : ControllerBase
[HttpPost("/instruct/image-variation/upload")]
public async Task ImageVariation(IFormFile file, [FromForm] string? provider = null,
[FromForm] string? model = null, [FromForm] List? states = null,
- [FromForm] string? agentId = null, [FromForm] string? templateName = null)
+ [FromForm] string? agentId = null)
{
var state = _services.GetRequiredService();
states?.ForEach(x => state.SetState(x.Key, x.Value, activeRounds: x.ActiveRounds, source: StateSource.External));
@@ -276,8 +275,7 @@ public class InstructModeController : ControllerBase
{
Provider = provider,
Model = model,
- AgentId = agentId,
- TemplateName = templateName
+ AgentId = agentId
});
imageViewModel.Content = message.Content;
diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs
index 47df077e..71c0d691 100644
--- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs
+++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs
@@ -1,5 +1,4 @@
using OpenAI.Images;
-using static System.Net.Mime.MediaTypeNames;
namespace BotSharp.Plugin.OpenAI.Providers.Image;