using System.ComponentModel;
using System.Collections.Generic;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
public partial class StorageBlobImageData
public Uri Url { get; set; }
public partial class Base64ImageData
public BinaryData Base64Json { get; set; }
public partial class ImageGenerations
public IReadOnlyList<StorageBlobImageData> StorageBlobData { get; }
public IReadOnlyList<Base64ImageData> Base64Data { get; }
public static void Main()
public static void UseUrl()
ImageGenerationOptions options = new ImageGenerationOptions();
options.ResposeFormat = ImageGenerationResponseFormat.Url;
OpenAIClient client = new OpenAIClient();
ImageGenerations result = client.GenerateImages(options);
foreach (var generatedImage in result.StorageBlobData)
BlobClient blobClient = new BlobClient(generatedImage.Url);
BlobDownloadResult download = blobClient.DownloadContent();
SaveToFile(download.Content.ToStream());
public static void UseBase64Json()
ImageGenerationOptions options = new ImageGenerationOptions();
options.ResposeFormat = ImageGenerationResponseFormat.Base64;
OpenAIClient client = new OpenAIClient();
ImageGenerations result = client.GenerateImages(options);
foreach (Base64ImageData generatedImage in result.Base64Data)
SaveToFile(generatedImage.Base64Json.ToStream());
public static void SaveToFile(Stream stream)
using (var fileStream = File.Create("MyImage.png"))
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
public partial class OpenAIClient
public virtual Response<ImageGenerations> GenerateImages(
ImageGenerationOptions imageGenerationOptions,
CancellationToken cancellationToken = default)
throw new NotImplementedException();
public partial class ImageGenerationOptions
public ImageGenerationResponseFormat? ResposeFormat { get; set; }
public readonly partial struct ImageGenerationResponseFormat : IEquatable<ImageGenerationResponseFormat>
private readonly string _value;
public ImageGenerationResponseFormat(string value)
_value = value ?? throw new ArgumentNullException(nameof(value));
private const string UrlValue = "url";
private const string Base64Value = "b64_json";
public static ImageGenerationResponseFormat Url { get; } = new ImageGenerationResponseFormat(UrlValue);
public static ImageGenerationResponseFormat Base64 { get; } = new ImageGenerationResponseFormat(Base64Value);
public static bool operator ==(ImageGenerationResponseFormat left, ImageGenerationResponseFormat right) => left.Equals(right);
public static bool operator !=(ImageGenerationResponseFormat left, ImageGenerationResponseFormat right) => !left.Equals(right);
public static implicit operator ImageGenerationResponseFormat(string value) => new ImageGenerationResponseFormat(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is ImageGenerationResponseFormat other && Equals(other);
public bool Equals(ImageGenerationResponseFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string ToString() => _value;