Skip to content
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

How can I tell when its done? #85

Open
PowellT opened this issue Aug 15, 2024 · 3 comments
Open

How can I tell when its done? #85

PowellT opened this issue Aug 15, 2024 · 3 comments

Comments

@PowellT
Copy link

PowellT commented Aug 15, 2024

I need to do something when the stream is complete?
onclose doesnt seem to be firing

any help appreciated

@a554878526
Copy link

When the stream completes is determined by the server, and each piece of the complete stream follows through \n\n

@joshmossas
Copy link

joshmossas commented Dec 11, 2024

To go into more detail, it really depends on the server implementation. Server sent events typically are implemented as a never ending stream so onclose will never fire unless the connection is closed by the client or the server.

To get around this many apis will send a "done" or "finished" event to notify the client that no more messages will be sent. For example it might look like this:

data: 1

data: 2

data: 3

event: done
data: stream is finished

So in that case you would add a listener to that done event to know when to close the connection.

@joshmossas
Copy link

joshmossas commented Dec 11, 2024

Another example: This is what a stream from ChatGPT looks like. Notice the [DONE] event at the end.
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants