Skip to content

Commit

Permalink
feat: Added Image.Bytes auto-property to get Base64 json as byte array.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 31, 2024
1 parent 6982847 commit 11f4947
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/libs/OpenAI/Image.Bytes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace OpenAI;

public partial class Image
{
/// <summary>
/// Returns bytes of base64-encoded JSON of the generated image.
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
public byte[] Bytes => B64Json == null || string.IsNullOrWhiteSpace(B64Json)
? throw new InvalidOperationException("The image is not available in base64 format.")
: Convert.FromBase64String(B64Json);
}
2 changes: 1 addition & 1 deletion src/libs/OpenAI/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net4.6.2;net6.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1724;CA2227</NoWarn>
<NoWarn>$(NoWarn);CA1724;CA2227;CA1819</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 11f4947

Please sign in to comment.