Skip to content

Commit

Permalink
com.openai.unity 5.2.2 (#121)
Browse files Browse the repository at this point in the history
- Fixed Image Generation for Azure
  • Loading branch information
StephenHodgson authored Nov 10, 2023
1 parent abdc30a commit 58cd5a7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Runtime/Chat/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Content(string text)

[Preserve]
public Content(Texture2D texture)
: this(ContentType.ImageUrl, $"data:image/jpeg;base64,{Convert.ToBase64String(texture.EncodeToPNG())}")
: this(ContentType.ImageUrl, $"data:image/png;base64,{Convert.ToBase64String(texture.EncodeToPNG())}")
{
}

Expand Down
3 changes: 2 additions & 1 deletion Runtime/Images/ImagesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public async Task<IReadOnlyDictionary<string, Texture2D>> GenerateImageAsync(
public async Task<IReadOnlyDictionary<string, Texture2D>> GenerateImageAsync(ImageGenerationRequest request, CancellationToken cancellationToken = default)
{
var payload = JsonConvert.SerializeObject(request, OpenAIClient.JsonSerializationOptions);
var response = await Rest.PostAsync(GetUrl("/generations"), payload, new RestParameters(client.DefaultRequestHeaders), cancellationToken);
var endpoint = GetUrl($"/generations{(client.Settings.Info.IsAzureDeployment ? ":submit" : string.Empty)}");
var response = await Rest.PostAsync(endpoint, payload, new RestParameters(client.DefaultRequestHeaders), cancellationToken);
return await DeserializeResponseAsync(response, cancellationToken);
}

Expand Down
2 changes: 2 additions & 0 deletions Runtime/OpenAISettingsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ public OpenAISettingsInfo(string resourceName, string deploymentId, string apiVe
public string BaseRequestUrlFormat { get; }

public bool UseOAuthAuthentication { get; }

internal bool IsAzureDeployment => BaseRequestUrlFormat.Contains(AzureOpenAIDomain);
}
}
2 changes: 1 addition & 1 deletion 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.2.1",
"version": "5.2.2",
"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 58cd5a7

Please sign in to comment.