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

Change API for streams #8208

Open
1 task done
pngwn opened this issue May 3, 2024 · 1 comment
Open
1 task done

Change API for streams #8208

pngwn opened this issue May 3, 2024 · 1 comment
Assignees
Labels
gradio_client Related to the one of the gradio client libraries

Comments

@pngwn
Copy link
Member

pngwn commented May 3, 2024

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.

The streaming API for the @gradio/client isn't really that nice. I think we should switch to an async iterator, we would go from this:

const app = Client.create();
const job = app.submit("/endpoint", body)

job.on("data", data => {
  // do something with data
})
job.on("status",status => {
  // do something with status
})

To this:

const app = Client.create();
const stream = app.submit("/endpoint", body)

for await (let event of stream) {
  console.log('<<', event.type); // 'status' | 'data'
  console.log('<<', event.data);
} 

Benefits:

  • its just nicer
  • fits into a linear await flow better which is the standard in JS now

Other thoughts

@freddyaboulton @abidlabs Should the python client follow a similar pattern and return an iterator for streams instead? I've seen this pattern quite a bit recently when working with streams and found it really nice.

@pngwn pngwn added the gradio_client Related to the one of the gradio client libraries label May 3, 2024
@pngwn pngwn added this to the @gradio/client 1.0 milestone May 3, 2024
@freddyaboulton
Copy link
Collaborator

I really like the suggestion @pngwn ! Would match the api of the python client

@pngwn pngwn self-assigned this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio_client Related to the one of the gradio client libraries
Projects
None yet
Development

No branches or pull requests

2 participants