From 0d6e81c4d23f295166e94f09784f2887cf5b8cac Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 5 Feb 2024 22:47:39 -0500 Subject: [PATCH] com.openai.unity 7.3.5 (#184) - Updated api key prefix checks to only be enforced for OpenAI domain - Fixed file name collisions when generating speech clips in parallel --- Runtime/Audio/AudioEndpoint.cs | 10 +++++++++- Runtime/OpenAIClient.cs | 2 +- package.json | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Runtime/Audio/AudioEndpoint.cs b/Runtime/Audio/AudioEndpoint.cs index 7e14ba37..b9996fbe 100644 --- a/Runtime/Audio/AudioEndpoint.cs +++ b/Runtime/Audio/AudioEndpoint.cs @@ -38,6 +38,8 @@ internal AudioEndpoint(OpenAIClient client) : base(client) { } /// protected override string Root => "audio"; + private static readonly object mutex = new object(); + /// /// Generates audio from the input text. /// @@ -57,7 +59,13 @@ public async Task> 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, diff --git a/Runtime/OpenAIClient.cs b/Runtime/OpenAIClient.cs index 5a5e6bd6..7e12a924 100644 --- a/Runtime/OpenAIClient.cs +++ b/Runtime/OpenAIClient.cs @@ -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)))) diff --git a/package.json b/package.json index 4fac15c3..f4f3a69c 100644 --- a/package.json +++ b/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": "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",