Skip to content

Commit

Permalink
com.openai.unity 7.3.5 (#184)
Browse files Browse the repository at this point in the history
- Updated api key prefix checks to only be enforced for OpenAI domain
- Fixed file name collisions when generating speech clips in parallel
  • Loading branch information
StephenHodgson authored Feb 6, 2024
1 parent bbc7b93 commit 0d6e81c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Runtime/Audio/AudioEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ internal AudioEndpoint(OpenAIClient client) : base(client) { }
/// <inheritdoc />
protected override string Root => "audio";

private static readonly object mutex = new object();

/// <summary>
/// Generates audio from the input text.
/// </summary>
Expand All @@ -57,7 +59,13 @@ public async Task<Tuple<string, AudioClip>> CreateSpeechAsync(SpeechRequest requ
_ => throw new NotSupportedException(request.ResponseFormat.ToString())
};
var payload = JsonConvert.SerializeObject(request, OpenAIClient.JsonSerializationOptions);
var clipName = $"{request.Voice}-{DateTime.UtcNow:yyyyMMddThhmmss}.{ext}";
string clipName;

lock (mutex)
{
clipName = $"{request.Voice}-{DateTime.UtcNow:yyyyMMddThhmmssff}.{ext}";
}

var clip = await Rest.DownloadAudioClipAsync(
GetUrl("/speech"),
audioFormat,
Expand Down
2 changes: 1 addition & 1 deletion Runtime/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override void SetupDefaultRequestHeaders()
{ "OpenAI-Beta", "assistants=v1"}
};

if (!Settings.Info.BaseRequestUrlFormat.Contains(OpenAISettingsInfo.AzureOpenAIDomain) &&
if (Settings.Info.BaseRequestUrlFormat.Contains(OpenAISettingsInfo.OpenAIDomain) &&
(string.IsNullOrWhiteSpace(Authentication.Info.ApiKey) ||
(!Authentication.Info.ApiKey.Contains(OpenAIAuthInfo.SecretKeyPrefix) &&
!Authentication.Info.ApiKey.Contains(OpenAIAuthInfo.SessionKeyPrefix))))
Expand Down
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": "7.3.4",
"version": "7.3.5",
"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 0d6e81c

Please sign in to comment.