Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

You Can't Even Make an AI Wrapper Chat App πŸ˜†πŸ«΅

DEV Community: tutorialΒ·ShuvoΒ·3 months ago
#eUM9PzRV
#dev#chat#await#const#fullscreen#article
Reading 0:00
15s threshold

"It's just a fetch call, bro." β€” Every junior dev, moments before learning a hard lesson. So you want to build a ChatGPT wrapper. Fair enough. It sounds embarrassingly simple β€” you've got an API key, a text box, and ambition. How hard can it be? Turns out: pretty hard. Not rocket science hard, but "oh god why is my chat broken on refresh" hard. Let's walk through the three stages of enlightenment. 🟒 Stage 1: The Junior Dev Move "Ship it. It works on my machine." The junior dev opens a blank React project, installs axios (or doesn't, and just uses fetch ), and writes something like this: Frontend: const res = await fetch ( ' /api/chat ' , { method : ' POST ' , body : JSON . stringify ({ msg : input }) }); const { result } = await res . json (); setReply ( result ); Enter fullscreen mode Exit fullscreen mode Backend: app . post ( ' /api/chat ' , async ( req , res ) => { const result = await ai . chat ( req . body . msg ); res . json ({ result }); }); Enter fullscreen mode Exit fullscreen mode Done.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More