Skip to content

fix: Update OpenAIApi.cs for chunks incomplete bug #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Runtime/OpenAIApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private async void DispatchRequest<T>(string path, string method, Action<List<T>
request.method = method;
request.SetHeaders(Configuration, ContentType.ApplicationJson);

var asyncOperation = request.SendWebRequest();

request.SendWebRequest();
bool isDone = false;
do
{
List<T> dataList = new List<T>();
Expand All @@ -122,10 +122,9 @@ private async void DispatchRequest<T>(string path, string method, Action<List<T>
foreach (string line in lines)
{
var value = line.Replace("data: ", "");

if (value.Contains("[DONE]"))
if (value.Contains("stop"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since value contains the entire chunk response, wouldn't this incorrectly set isDone to true if the delta content contained the word stop? I think a better solution would be to only set isDone when the value contains [DONE]. Or explicitly see if it contains "finish_reason":"stop"

{
onComplete?.Invoke();
isDone = true;
break;
}

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

await Task.Yield();
}
while (!asyncOperation.isDone && !token.IsCancellationRequested);
while (!isDone);

onComplete?.Invoke();
}
Expand Down