Back to course overview
Module 5Putting AI inside your app 40 min
Lab: Add the AI feature end-to-end
Deploy your proxy, wire the Reflect button into the detail screen, and generate real insights for a real entry.
Outcome of this lab
A working, shippable AI feature: tap Reflect on an entry and get a model-generated title, mood, and reflection — with a spinner, error handling, and a securely stored key.
Step 1 — Deploy the proxy
- 1Create the serverless project and add the
reflectfunction from the lesson. - 2Set
ANTHROPIC_API_KEYas a secret environment variable in the dashboard. - 3Deploy and confirm it works with the curl command. You should get back JSON with title, mood, and reflection.
Step 2 — Wire the app
- 1Add
AppConfig.swiftwith your proxy base URL,Insights.swift,InsightsService.swift, andReflectButton.swift. - 2In
EntryDetailView, showReflectButton(entry: entry)when the entry has noaiTitleyet, and show the generated title/mood/reflection when it does. - 3Build (⌘B) and fix any compile errors — paste them to your assistant if needed.
Step 3 — Try it for real
- 1Run the app, open an entry with a few sentences of real text, and tap Reflect.
- 2Watch the spinner, then the insights appear and persist. Relaunch — they're still there (they're saved on the Entry).
- 3Turn off Wi-Fi and tap Reflect on a fresh entry to see the failure + retry path. Turn it back on and retry.
Add your guardrails now
Before moving on: cap the entry length you send (e.g. 4,000 characters), and disable Reflect while a call is in flight. These two lines prevent both runaway costs and duplicate requests — exactly the kind of thing that bites you after launch.
bashbash
git add .
git commit -m "AI Reflect feature via secure proxy, with loading + error states"This is the milestone lab. You now have an app that stores data locally and uses a language model through a secure backend — the full stack of a modern AI app, built by directing AI and understanding each piece.