diff --git a/Runtime/OpenAIApi.cs b/Runtime/OpenAIApi.cs index 5dd54f6..6468957 100644 --- a/Runtime/OpenAIApi.cs +++ b/Runtime/OpenAIApi.cs @@ -112,6 +112,7 @@ private async void DispatchRequest(string path, string method, Action request.SetHeaders(Configuration, ContentType.ApplicationJson); var asyncOperation = request.SendWebRequest(); + bool isDone = false; do { @@ -124,7 +125,7 @@ private async void DispatchRequest(string path, string method, Action if (value.Contains("[DONE]")) { - onComplete?.Invoke(); + isDone = true; break; } @@ -144,7 +145,7 @@ private async void DispatchRequest(string path, string method, Action await Task.Yield(); } - while (!asyncOperation.isDone && !token.IsCancellationRequested); + while (!isDone); onComplete?.Invoke(); }