From 6dd37afc3eccdf5889c6cbbf490e4ecdb4a9dd8e Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Wed, 8 Nov 2023 16:25:58 -0500 Subject: [PATCH] com.openai.unity 5.1.3 (#116) - Fix Image Generation result local cache file path (for real!) --- .../com.openai.unity/Runtime/Images/ImagesEndpoint.cs | 9 ++++++--- OpenAI/Packages/com.openai.unity/package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/OpenAI/Packages/com.openai.unity/Runtime/Images/ImagesEndpoint.cs b/OpenAI/Packages/com.openai.unity/Runtime/Images/ImagesEndpoint.cs index 5569d7e4..6048e275 100644 --- a/OpenAI/Packages/com.openai.unity/Runtime/Images/ImagesEndpoint.cs +++ b/OpenAI/Packages/com.openai.unity/Runtime/Images/ImagesEndpoint.cs @@ -289,6 +289,9 @@ public async Task> CreateImageVariationAs return await DeserializeResponseAsync(response, cancellationToken); } + private const string LocalFilePrefix = "file://"; + private readonly char[] localFilePrefixCharArray = LocalFilePrefix.ToCharArray(); + private async Task> DeserializeResponseAsync(Response response, CancellationToken cancellationToken = default) { response.Validate(EnableDebug); @@ -319,7 +322,7 @@ async Task DownloadAsync(ImageResult result) await File.WriteAllBytesAsync(localFilePath, imageData, cancellationToken); } - resultImagePath = localFilePath; + resultImagePath = $"{LocalFilePrefix}{localFilePath}"; } else { @@ -327,11 +330,11 @@ async Task DownloadAsync(ImageResult result) } await Awaiters.UnityMainThread; - var texture = await Rest.DownloadTextureAsync($"file://{resultImagePath}", cancellationToken: cancellationToken); + var texture = await Rest.DownloadTextureAsync(resultImagePath, cancellationToken: cancellationToken); if (Rest.TryGetDownloadCacheItem(resultImagePath, out localFilePath)) { - images.TryAdd(localFilePath, texture); + images.TryAdd(localFilePath.TrimStart(localFilePrefixCharArray), texture); } else { diff --git a/OpenAI/Packages/com.openai.unity/package.json b/OpenAI/Packages/com.openai.unity/package.json index 2cde6a8c..8f9571dd 100644 --- a/OpenAI/Packages/com.openai.unity/package.json +++ b/OpenAI/Packages/com.openai.unity/package.json @@ -3,7 +3,7 @@ "displayName": "OpenAI", "description": "A OpenAI package for the Unity Game Engine to use GPT-4, GPT-3.5, GPT-3 and Dall-E though their RESTful API (currently in beta).\n\nIndependently developed, this is not an official library and I am not affiliated with OpenAI.\n\nAn OpenAI API account is required.", "keywords": [], - "version": "5.1.2", + "version": "5.1.3", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.openai.unity#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.openai.unity/releases",