diff --git a/Runtime/OpenAIApi.cs b/Runtime/OpenAIApi.cs index 00e5572..2378eab 100644 --- a/Runtime/OpenAIApi.cs +++ b/Runtime/OpenAIApi.cs @@ -112,8 +112,8 @@ private async void DispatchRequest(string path, string method, Action request.method = method; request.SetHeaders(Configuration, ContentType.ApplicationJson); - var asyncOperation = request.SendWebRequest(); - + request.SendWebRequest(); + bool isDone = false; do { List dataList = new List(); @@ -122,10 +122,9 @@ private async void DispatchRequest(string path, string method, Action foreach (string line in lines) { var value = line.Replace("data: ", ""); - - if (value.Contains("[DONE]")) + if (value.Contains("stop")) { - onComplete?.Invoke(); + isDone = true; break; } @@ -145,7 +144,7 @@ private async void DispatchRequest(string path, string method, Action await Task.Yield(); } - while (!asyncOperation.isDone && !token.IsCancellationRequested); + while (!isDone); onComplete?.Invoke(); }