fix file selection

This commit is contained in:
Jicheng Lu 2025-03-31 21:21:45 -05:00
parent adfb8f4fc4
commit c84410b823
5 changed files with 13 additions and 24 deletions

View file

@ -8,9 +8,9 @@ public class SelectFileOptions
public string? Provider { get; set; }
/// <summary>
/// Llm model id
/// Llm model
/// </summary>
public string? ModelId { get; set; }
public string? Model { get; set; }
/// <summary>
/// Agent id

View file

@ -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<IInstructHook>();
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();

View file

@ -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<RoleDialogModel> { message });
var content = response?.Content ?? string.Empty;

View file

@ -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<ImageGenerationViewModel> ImageVariation(IFormFile file, [FromForm] string? provider = null,
[FromForm] string? model = null, [FromForm] List<MessageState>? states = null,
[FromForm] string? agentId = null, [FromForm] string? templateName = null)
[FromForm] string? agentId = null)
{
var state = _services.GetRequiredService<IConversationStateService>();
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;

View file

@ -1,5 +1,4 @@
using OpenAI.Images;
using static System.Net.Mime.MediaTypeNames;
namespace BotSharp.Plugin.OpenAI.Providers.Image;