Skip to content

Commit

Permalink
com.openai.unity 5.1.3 (#116)
Browse files Browse the repository at this point in the history
- Fix Image Generation result local cache file path (for real!)
  • Loading branch information
StephenHodgson authored Nov 8, 2023
1 parent 5cd0f25 commit 6dd37af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ public async Task<IReadOnlyDictionary<string, Texture2D>> CreateImageVariationAs
return await DeserializeResponseAsync(response, cancellationToken);
}

private const string LocalFilePrefix = "file://";
private readonly char[] localFilePrefixCharArray = LocalFilePrefix.ToCharArray();

private async Task<IReadOnlyDictionary<string, Texture2D>> DeserializeResponseAsync(Response response, CancellationToken cancellationToken = default)
{
response.Validate(EnableDebug);
Expand Down Expand Up @@ -319,19 +322,19 @@ async Task DownloadAsync(ImageResult result)
await File.WriteAllBytesAsync(localFilePath, imageData, cancellationToken);
}

resultImagePath = localFilePath;
resultImagePath = $"{LocalFilePrefix}{localFilePath}";
}
else
{
resultImagePath = result.Url;
}

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
{
Expand Down
2 changes: 1 addition & 1 deletion OpenAI/Packages/com.openai.unity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6dd37af

Please sign in to comment.