Skip to content

Commit db8b4a7

Browse files
fix: Update OpenAIApi.cs for chunks incomplete bug
1 parent 1928201 commit db8b4a7

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Runtime/OpenAIApi.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ private async void DispatchRequest<T>(string path, string method, Action<List<T>
112112
request.method = method;
113113
request.SetHeaders(Configuration, ContentType.ApplicationJson);
114114

115-
var asyncOperation = request.SendWebRequest();
116-
115+
request.SendWebRequest();
116+
bool isDone = false;
117117
do
118118
{
119119
List<T> dataList = new List<T>();
@@ -122,10 +122,9 @@ private async void DispatchRequest<T>(string path, string method, Action<List<T>
122122
foreach (string line in lines)
123123
{
124124
var value = line.Replace("data: ", "");
125-
126-
if (value.Contains("[DONE]"))
125+
if (value.Contains("stop"))
127126
{
128-
onComplete?.Invoke();
127+
isDone = true;
129128
break;
130129
}
131130

@@ -145,7 +144,7 @@ private async void DispatchRequest<T>(string path, string method, Action<List<T>
145144

146145
await Task.Yield();
147146
}
148-
while (!asyncOperation.isDone && !token.IsCancellationRequested);
147+
while (!isDone);
149148

150149
onComplete?.Invoke();
151150
}

0 commit comments

Comments
 (0)