From 11f4947c15b36e6f2d2953a8e18bd928c0113ea8 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Fri, 30 Aug 2024 04:10:54 +0400 Subject: [PATCH] feat: Added Image.Bytes auto-property to get Base64 json as byte array. --- src/libs/OpenAI/Image.Bytes.cs | 12 ++++++++++++ src/libs/OpenAI/OpenAI.csproj | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/libs/OpenAI/Image.Bytes.cs diff --git a/src/libs/OpenAI/Image.Bytes.cs b/src/libs/OpenAI/Image.Bytes.cs new file mode 100644 index 00000000..1af3b0c9 --- /dev/null +++ b/src/libs/OpenAI/Image.Bytes.cs @@ -0,0 +1,12 @@ +namespace OpenAI; + +public partial class Image +{ + /// + /// Returns bytes of base64-encoded JSON of the generated image. + /// + /// + public byte[] Bytes => B64Json == null || string.IsNullOrWhiteSpace(B64Json) + ? throw new InvalidOperationException("The image is not available in base64 format.") + : Convert.FromBase64String(B64Json); +} \ No newline at end of file diff --git a/src/libs/OpenAI/OpenAI.csproj b/src/libs/OpenAI/OpenAI.csproj index 3594c3b6..a8f2ec2e 100644 --- a/src/libs/OpenAI/OpenAI.csproj +++ b/src/libs/OpenAI/OpenAI.csproj @@ -2,7 +2,7 @@ netstandard2.0;net4.6.2;net6.0;net8.0 - $(NoWarn);CA1724;CA2227 + $(NoWarn);CA1724;CA2227;CA1819