Navigation überspringen
I made a 4096-token LLM plan a trip without hallucinating half of it.
0:00 / 0:31

I made a 4096-token LLM plan a trip without hallucinating half of it.

JC Builds

@JC_builds2518 Follower

Auf X besuchen

14.734 Aufrufe

I made a 4096-token LLM plan a trip without hallucinating half of it. No API calls. Everything runs on-device. Just type "tokyo" and see a full day-by-day itinerary. Maps, food, transportation... Here's exactly how it works 👇

29 Kommentare

Kommentare aus dem Originalbeitrag auf X (Twitter)

  • Profilbild von JC Builds

    @JC_builds

    First thing I learned: don't make the model build the itinerary. Small on-device models fall apart on long output (dropped days, invented times, repeated stops). So the LLM only returns tiny JSON: day titles + which spots go where. Then Swift composes the plan and clusters the stops by location, so each day is actually walkable instead of zig-zagging across the city. Model does taste. Code does structure.

    2 Likes

  • Profilbild von JC Builds

    @JC_builds

    Second: a local model has no idea what's actually in a city. So I ground everything. Web search for candidate spots → LLM extracts them → Apple MapKit geocodes each one. Then I throw out anything more than ~60km from the city center. Kills the "same-name restaurant in another country" problem instantly.

    2 Likes

  • Profilbild von JC Builds

    @JC_builds

    Third, the painful part: on-device context is TINY. Apple Intelligence gives you 4,096 tokens. Input + schema + instructions, all of it. The numbers I landed on after WAYY too much trial and error: - truncate scraped pages to 1,400 chars - max 3 detail follow-ups per city - 15 activities per extraction - temperature 0.3 That's what keeps it accurate and still finishes in ~2 min.

    3 Likes

  • Profilbild von JC Builds

    @JC_builds

    Last: constrain the output, then assume it lies anyway. Every call uses a JSON schema. It still hands back a bare array instead of the object maybe half the time (so I just decode both shapes and move on). Runs on a small GGUF model (llama.cpp) locally, but falls back to Apple Intelligence when nothing's downloaded. Ask me anything about any piece!

    1 Like

  • Profilbild von Gabriele Scotto di Vettimo

    @gabsdv

    “Model does the taste, code does the structure” split is really important. The best AI-driven apps I’ve seen had this type of split

    2 Likes

  • Profilbild von JC Builds

    @JC_builds

    Totally agree, it 10x's the quality of the output for tasks like this (not an actual metri, just a feel😅)

    1 Like

  • Profilbild von Ishaan Rawat

    @IshaanRawat

    I am also building an app which uses on device model. I was working on getting the results I want with such a low token limit. This will be super helpful, thanks 😊

    2 Likes

  • Profilbild von JC Builds

    @JC_builds

    Awesome, happy to help! What are you working on?

  • Profilbild von Mykhailo Sorochuk

    @sir4K_zen

    smart move keeping the model to tiny JSON, lets the on device LLM stay focused and avoid hallucinations

    2 Likes

  • Profilbild von JC Builds

    @JC_builds

    It tends to work a lot better this way

  • Profilbild von Arne Wiese

    @wiesson

    Can I benchmark it?

    1 Like

  • Profilbild von JC Builds

    @JC_builds

    Benchmark it how?

  • Profilbild von Arne Wiese

    @wiesson

    Dm?

    1 Like

  • Profilbild von JC Builds

    @JC_builds

    Sure shoot me a DM

  • Profilbild von Nicoles hudgins

    @NicolesHudgins

    How big is the model? Like how many parameters?

    1 Like

  • Profilbild von JC Builds

    @JC_builds

    There are a variety of models you can chose from. But the main model I use is Qwen3.5 4B Q4

  • Profilbild von Maya Srinivasan

    @imayasrinivasan

    that's actually wild, no api calls is the dream for stuff like this

    1 Like

  • Profilbild von Rohit Kashyap

    @rohit_jsfreaky

    a 4096 token model planning a real itinerary fully on device is a neat constraint flex

    1 Like

  • Profilbild von JC Builds

    @JC_builds

    Appreciate it! It was a fun problem to tackle

  • Profilbild von kohodono

    @kohodono

    Do you bundle the model inside the app, or you download it after install? I’m also building an app with on device llm, but this is unsolved dilemma for me. On one hand I want to provide value to user right after install, on the other - big app size can scare users away. How do you solve it?

    1 Like