using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
public static void Main()
OpenAIClient client = new();
string prompt = "The concept for a living room that pulls from mid-century design elements while bringing in softer, current shapes for a"
+ " stylish juxtaposition. It's a unique, personalized space with a touch of nostalgia. Using autumnal hues, including colors like copper,"
+ " burnt orange, terracotta, and amber, that bring a sense of humility. Featuring expressive marble with deep veining in a variety of"
+ " colors to add character and depth. Stone and rock in light and dark variations adding texture, bringing a touch of nature to a space."
+ " They can serve as bold wall accents, drawing attention to specific elements.";
ImageGenerationOptions options = new()
Quality = ImageQuality.Hd,
Size = ImageSize.Size1792x1024,
Response<ImageGenerationResultCollection> response = client.GetImageGenerations("dall-e-3", prompt, options);
ImageGenerationResultCollection results = response.Value;
BinaryData data = results[0].ImageBinaryDataSource.Get();
Stream stream = data.ToStream();
using (var fileStream = File.Create("C:\\AppData\\Images\\" + Guid.NewGuid().ToString() + ".png"))
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
public partial class OpenAIClient
public virtual Response<ImageGenerationResultCollection> GetImageGenerations(string deploymentName, string prompt, ImageGenerationOptions options = default, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public OpenAIClient() { }
public partial class ImageGenerationOptions
public ImageGenerationOptions() { }
public int? ImageCount { get; set; }
public ImageQuality? Quality { get; set; }
public ImageResponseFormat? ResponseFormat { get; set; }
public ImageSize? Size { get; set; }
public ImageStyle? Style { get; set; }
public string User { get; set; }
[DebuggerTypeProxy(typeof(ImageGenerationResultCollectionDebugView))]
public partial class ImageGenerationResultCollection : ReadOnlyCollection<ImageGenerationResult>
internal ImageGenerationResultCollection(IEnumerable<ImageGenerationResult> items, DateTimeOffset created) : base(items.ToList())
public DateTimeOffset Created { get; }
internal class ImageGenerationResultCollectionDebugView
private ImageGenerationResultCollection BaseCollection { get; }
public ImageGenerationResultCollectionDebugView(ImageGenerationResultCollection collection)
BaseCollection = collection;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public List<ImageGenerationResult> Items
return BaseCollection.ToList();
public DateTimeOffset Created
return BaseCollection.Created;
public partial class ImageGenerationResult
internal ImageGenerationResult(Uri imageUri, string revisedPrompt)
ImageBinaryDataSource = new BinaryDataSource(imageUri);
RevisedPrompt = revisedPrompt;
internal ImageGenerationResult(string imageBase64EncodedString, string revisedPrompt)
byte[] bytes = Convert.FromBase64String(imageBase64EncodedString);
ImageBinaryDataSource = new BinaryDataSource(new BinaryData(bytes));
RevisedPrompt = revisedPrompt;
public BinaryDataSource ImageBinaryDataSource { get; }
public string RevisedPrompt { get; }
public class BinaryDataSource
public BinaryDataSource(BinaryData data)
public BinaryDataSource(Uri uri)
public BinaryDataSource(string filePath)
public BinaryData Data { get; }
public string FilePath { get; }
public BinaryData Get(CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public ValueTask<BinaryData> GetAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public readonly partial struct ImageQuality : IEquatable<ImageQuality>
private readonly string _value;
public ImageQuality(string value)
_value = value ?? throw new ArgumentNullException(nameof(value));
private const string StandardValue = "standard";
private const string HdValue = "hd";
public static ImageQuality Standard { get; } = new ImageQuality(StandardValue);
public static ImageQuality Hd { get; } = new ImageQuality(HdValue);
public static bool operator ==(ImageQuality left, ImageQuality right) => left.Equals(right);
public static bool operator !=(ImageQuality left, ImageQuality right) => !left.Equals(right);
public static implicit operator ImageQuality(string value) => new ImageQuality(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is ImageQuality other && Equals(other);
public bool Equals(ImageQuality other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string ToString() => _value;
public readonly partial struct ImageResponseFormat : IEquatable<ImageResponseFormat>
private readonly string _value;
public ImageResponseFormat(string value)
_value = value ?? throw new ArgumentNullException(nameof(value));
private const string UrlValue = "url";
private const string Base64Value = "b64_json";
public static ImageResponseFormat Url { get; } = new ImageResponseFormat(UrlValue);
public static ImageResponseFormat Base64 { get; } = new ImageResponseFormat(Base64Value);
public static bool operator ==(ImageResponseFormat left, ImageResponseFormat right) => left.Equals(right);
public static bool operator !=(ImageResponseFormat left, ImageResponseFormat right) => !left.Equals(right);
public static implicit operator ImageResponseFormat(string value) => new ImageResponseFormat(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is ImageResponseFormat other && Equals(other);
public bool Equals(ImageResponseFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string ToString() => _value;
public readonly partial struct ImageSize : IEquatable<ImageSize>
private readonly string _value;
public ImageSize(string value)
_value = value ?? throw new ArgumentNullException(nameof(value));
private const string Size256x256Value = "256x256";
private const string Size512x512Value = "512x512";
private const string Size1024x1024Value = "1024x1024";
private const string Size1792x1024Value = "1792x1024";
private const string Size1024x1792Value = "1024x1792";
public static ImageSize Size256x256 { get; } = new ImageSize(Size256x256Value);
public static ImageSize Size512x512 { get; } = new ImageSize(Size512x512Value);
public static ImageSize Size1024x1024 { get; } = new ImageSize(Size1024x1024Value);
public static ImageSize Size1792x1024 { get; } = new ImageSize(Size1792x1024Value);
public static ImageSize Size1024x1792 { get; } = new ImageSize(Size1024x1792Value);
public static bool operator ==(ImageSize left, ImageSize right) => left.Equals(right);
public static bool operator !=(ImageSize left, ImageSize right) => !left.Equals(right);
public static implicit operator ImageSize(string value) => new ImageSize(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is ImageSize other && Equals(other);
public bool Equals(ImageSize other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string ToString() => _value;
public readonly partial struct ImageStyle : IEquatable<ImageStyle>
private readonly string _value;
public ImageStyle(string value)
_value = value ?? throw new ArgumentNullException(nameof(value));
private const string NaturalValue = "natural";
private const string VividValue = "vivid";
public static ImageStyle Natural { get; } = new ImageStyle(NaturalValue);
public static ImageStyle Vivid { get; } = new ImageStyle(VividValue);
public static bool operator ==(ImageStyle left, ImageStyle right) => left.Equals(right);
public static bool operator !=(ImageStyle left, ImageStyle right) => !left.Equals(right);
public static implicit operator ImageStyle(string value) => new ImageStyle(value);
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj) => obj is ImageStyle other && Equals(other);
public bool Equals(ImageStyle other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => _value?.GetHashCode() ?? 0;
public override string ToString() => _value;
#endregion AZURE.AI.OPENAI