Consume streaming data from OpenAI with vanilla JavaScript

by umaaron 4/19/2023, 9:49 PMwith 2 comments

by umaaron 4/19/2023, 9:52 PM

Hey HN, have seen a lot of AI demos recently using libraries/frameworks for what is effectively an API call - so thought to showcase how this could be done with vanilla JavaScript. Turns out response.body is an async iterable, so you can do something like:

  for await (const chunk of response.body) { // use chunk }

by sbrickson 4/19/2023, 9:55 PM

why everyone likes JavaScript so much? :)