I was integrating some AI featured into wyd.chat, an app I made that gives you Spotify wrapped type analytics for your iMessage. Most texted person, most popular group chat – that kinda stuff. You should go download it.
The ChatGPT integration would allow you to ask "What should I get my friend for their birthday", have GPT comb through your texts and (hopefully?) make some stellar recommendations.
While doing the integration, I ran into a very interesting bug and I thought it would be fun to outline my debugging process to illustrate how real bugs get solved.
The Setup
To set some context:
npm i ai
) with it's (currently) experimental function support. I wired everything up according to instruction, and..
... it didn't work lol.
The function handler I provided just would not be called.
This is where things got interesting. A younger me would have given up, thinking some weird combination of Tauri + the ai sdk is not compatible. Wiser Fardeem knows better. I know that it's javascript all the way down. It's literally only some network requests – stuff I feel very comfortable with.
Time to get coffee and get to the bottom of this.
This is obviously shortened for clarity and with a lot of hindsight and the process was pretty confusing when I was in it. But, the key principle is the same.
The lesson.
You don't want to debug by changing things and hoping things "fix" themselves. It's code all the way down. Try to figure out the distict areas where the problem might be and scope down until you get to a point where things work. Then, diff your checkpoint to your project. Systematic debugging is the only way to go.