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

Issues with Server Sent Events Client #1754

Closed
mcgear opened this issue Sep 8, 2023 · 7 comments
Closed

Issues with Server Sent Events Client #1754

mcgear opened this issue Sep 8, 2023 · 7 comments

Comments

@mcgear
Copy link
Contributor

mcgear commented Sep 8, 2023

Having a bit of an issue getting a fresh implementation going of an SSE client.

We are doing some work with OpenAI through Azure and are trying to stream the responses back to the UI.

If you check out our project Communit Chat you can run it with deno task start and then if you navigate to /api/openaistream/gpt-35-turbo you'll see that the API is responding with SSE and that the story comes in written in chunks.

The issue is that i can't figure out how to get an Island together that renders the chunks into view. We are trying in the islands/TextStream.tsx but I am running into issues.

  1. EventSource is not defined error is thrown due to there not being a Deno EventSource definition #10298
  2. When i try to use the third party module from here I get an error: caught (in promise) TypeError: reader is not async iterable
    at #fetch (mod.ts:124:35)

Any help in what i am doing wrong would be awesome, and i figure at the end of this we can PR into the docs a page on Server/Client SSE in Deno Fresh.

Thanks for the help!

@smitssjors
Copy link
Contributor

https://github.com/denoland/pixelpage Is implemented using SSE. Checkout islands/Pixels.tsx and routes/api/listen.ts. Also make sure that the events are properly formatted (e.g., data: some text\n\n).

I hope this helps

@mcgear
Copy link
Contributor Author

mcgear commented Sep 12, 2023

I was working on trying this out, but the biggest issue i have is that it says BroadcastChannel and EventSource are not defined. Trying to see what i missed to have those included. I see your on fresh version 1.2, not sure if that is the issue

@mcgear
Copy link
Contributor Author

mcgear commented Sep 12, 2023

Well that was easy, i didn't realize i needed the --unstable flag for those 2 to work.

@mcgear
Copy link
Contributor Author

mcgear commented Sep 12, 2023

Alright, this is working for me now, i am able to stream stuff in, however, the EventSource just keeps reconnecting and calling the API over and over again. Any thoughts on how i can make the EventSource only execute once?

@mcgear
Copy link
Contributor Author

mcgear commented Sep 13, 2023

I was able to address this issue by sending a [DONE] event at the end of the stream and listening for that on the client side, which allows me to then close the connection. This can probably be considered done in terms of my issues.

Is there any value in my documenting the entire process for SSE in the docs for Fresh?

Thanks for the help @smitssjors

@marvinhagemeister
Copy link
Collaborator

FYI: We've just switched over from SSE to websockets to establish a connection in development mode in #1943 .

@sebringj
Copy link

sebringj commented Dec 30, 2023

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

4 participants