#pragma warning disable OPENAI001 using OpenAI.Images; namespace BotSharp.Plugin.OpenAI.Providers.Image; public partial class ImageCompletionProvider { /// /// Composes multiple images into a single image using OpenAI's image edit API /// /// The agent making the request /// The message containing the composition prompt /// Array of image streams to compose /// Array of corresponding file names /// RoleDialogModel containing the composed image(s) public async Task GetImageComposition(Agent agent, RoleDialogModel message, Stream[] images, string[] imageFileNames) { var client = ProviderHelper.GetClient(Provider, _model, _services); var (prompt, imageCount, options) = PrepareEditOptions(message); var imageClient = client.GetImageClient(_model); // Use the new extension method to support multiple images options.ResponseFormat = "b64_json"; options.Quality = "medium"; options.Background = "auto"; options.Size = GeneratedImageSize.Auto; var response = imageClient.GenerateImageEdits(images, imageFileNames, prompt, imageCount, options); var generatedImageCollection = response.Value; var generatedImages = GetImageGenerations(generatedImageCollection, options.ResponseFormat); var content = string.Join("\r\n", generatedImages.Where(x => !string.IsNullOrWhiteSpace(x.Description)).Select(x => x.Description)); var responseMessage = new RoleDialogModel(AgentRole.Assistant, content) { CurrentAgentId = agent.Id, MessageId = message?.MessageId ?? string.Empty, GeneratedImages = generatedImages }; return await Task.FromResult(responseMessage); } }