Consume Web streams from OpenAI using vanilla JavaScript - NO DEPENDENCIES!

  Рет қаралды 2,528

Umar Hansa

Umar Hansa

Күн бұрын

Find the code here: umaar.com/dev-tips/269-web-st... and while you're there, signup for the Dev Tips mailing list to get more videos and tips like this one!
Chapters:
00:00:00 - What we're going to achieve
00:01:30 - Making a Fetch Request
00:03:01 - Non-streamed data
00:03:50 - Streaming the data
0:05:20 - Decoding Streamed Data
0:09:43 - Running the Script with Node JS
0:10:58 - Adding an Abort Controller
0:12:17 - Recap of Fetch API Streaming
0:12:47 - Conclusion and recap

Пікірлер: 23
@theeFaris
@theeFaris 11 күн бұрын
fantastic, a super simple minimalistic and working code
@UmarHansa
@UmarHansa Жыл бұрын
00:01:30 - Making a Fetch Request 00:03:01 - Non-streamed data 00:03:50 - Streaming the data 0:05:20 - Decoding Streamed Data 0:09:43 - Running the Script with Node JS 0:10:58 - Adding an Abort Controller 0:12:17 - Recap of Fetch API Streaming 0:12:47 - Conclusion and recap
@rhysm8167
@rhysm8167 Ай бұрын
Brilliant. Awsome mate. Thank you.
@johnm8358
@johnm8358 Жыл бұрын
Nice, love your videos
@michaeldausmann6066
@michaeldausmann6066 11 ай бұрын
nice content, well explained. for await is cool. also the destructuring of the json was interesting, I haven't used that before, nice exposition.
@islamabo0
@islamabo0 Жыл бұрын
Your videos are the best. I don't miss videos nor shorts ❤
@wboumans
@wboumans Ай бұрын
Thx, just what i needed!
@wobsoriano
@wobsoriano 9 ай бұрын
Awesome vid. Only thing that'll stop me from doing open ai requests in the browser is exposing the API keys. That's why I always end up using a server so I can authenticate a user and not expose API keys + Server Sent events
@elliotjunemusic
@elliotjunemusic Жыл бұрын
SOOOO badaasss, omg - Is see practical ways I could use that - didn't even know streaming was that ... simple in a sens (obvisouly considering the API you're consuming)
@theclarkofben84
@theclarkofben84 Жыл бұрын
Nice work, man
@sashirestela8572
@sashirestela8572 Жыл бұрын
For demo it is fine to call the OpenAI endpoint from the web side, but it is bad for other purposes because your API Key remains exposed to being stolen easily. It is more recommended to made the call on the server side, IMHO.
@ahmad-murery
@ahmad-murery Жыл бұрын
Very interesting example, I like doing my things using vanilla JS as much as I can. It will be very useful if you can explain more browser's web APIs. Thanks Umar👍🚀
@UmarHansa
@UmarHansa Жыл бұрын
Browsers are a lot more capable now! I'll try and cover more vanilla JS techniques soon, thank you Ahmad!
@ahmad-murery
@ahmad-murery Жыл бұрын
@@UmarHansa I'll be waiting patiently
@user-yf8hr1fe5u
@user-yf8hr1fe5u Жыл бұрын
Great tutorial! One wired bug that I've encountered if anyone is interested (not in the video) The 1st text content is missing. It turned out that, the 1st chunk in my response body contains 2 data pieces (just like the last one), and the 1st piece which looks like this "choices":[{"delta":{"role":"assistant"},"index":0,"finish_reason":null}] has no "content" property in "delta" and should be excluded like the "data: [DONE]".
@UmarHansa
@UmarHansa Жыл бұрын
Thanks for sharing!
@sergiomartin8935
@sergiomartin8935 Жыл бұрын
Great!
@_nikeee
@_nikeee Жыл бұрын
If the API would work with GET instead of POST, you could just use EventSource, since streaming just seems to be SSE in this case
@beernutz
@beernutz Жыл бұрын
Very cool video! Thank you! What is your coding setup? It looks like a bit more than autocomplete going on there.
@UmarHansa
@UmarHansa Жыл бұрын
Thanks! VS Code with Zen mode on, dracula theme, and GitHub CoPilot. Browser is Firefox DevTools
@jimshtepa5423
@jimshtepa5423 10 ай бұрын
what is the plugin that shows you content of console.log?
@vlkf
@vlkf Жыл бұрын
3:04 - what plugin shows this 2letter hotkeys to be able to navigate to any place in code? I wonder can i found same for jetBrains ide
@UmarHansa
@UmarHansa Жыл бұрын
AceJump
🔴  Build the Uber clone in React Native (Tutorial for Beginners)
3:43:51
Physicists Have Proven That the Universe Does Not Exist!
11:01
TheSimplySpace
Рет қаралды 8 М.
How Many Balloons Does It Take To Fly?
00:18
MrBeast
Рет қаралды 180 МЛН
Зачем он туда залез?
00:25
Vlad Samokatchik
Рет қаралды 3,3 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 12 МЛН
AI Video summaries: this will change how we consume videos!
8:05
🛑  Learn to use OpenAI API by building ChatGPT (super simple!) | React Node.js
1:05:13
Ranking The Most Popular Javascript Frameworks 2023
24:43
developedbyed
Рет қаралды 155 М.
Train ChatGPT-4 with your own data
13:19
Coding Nexus
Рет қаралды 6 М.
Learn JavaScript With This ONE Project!
1:10:26
Tech With Tim
Рет қаралды 679 М.
How to Learn Javascript in 2023 (From ZERO)
8:04
Andy Sterkowitz
Рет қаралды 292 М.
Build An AI Image Generator With OpenAI & Node.js
36:19
Traversy Media
Рет қаралды 159 М.
Building AI-Powered JavaScript Apps Is Way Easier Than You Think
16:01
Vite Crash Course | Faster Alternative To CRA
16:24
Traversy Media
Рет қаралды 193 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 61 МЛН
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 2,7 МЛН
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,9 МЛН