Case study · AI / ML engineering · Oct–Nov 2026
OrderSLM
A small AI model that takes food orders from chat
Customers text restaurants things like "CAN I GET A MEDIUM DRIP COFFE… ACTUALLY MAKE IT 2 MUFFINS". I built a system that turns chats like that into an exact, menu-checked order, using a 0.8-billion-parameter model I fine-tuned that's small enough to run on a laptop. Prices and totals are always computed by code, never by the AI. I measured every choice along the way: which big model teaches best per dollar, which small model learns best, and what shrinking it for deployment costs.
What it does
A real example from the evaluation set, answered by the final model. The chat is a written test conversation, not a real customer. (1) The four messages it got. (2) What the model proposed, with a quote from the chat backing each fact. (3) The code checks that against the menu and computes the price.
-
drip_coffee · medium · ×1
"A MEDIUM DRIP COFFE" -
muffin · blueberry · ×2
"A BLUBERRY MUFFIN", "2 MUFFINS" - pickup at 08:45 · name Ana · pays by card
- intent: PLACE_ORDER · typos, caps and the change of mind all handled
| Drip Coffee, Medium 12 oz | $2.75 |
| 2 × Muffin, Blueberry | $6.50 |
| Total (pickup) | $9.25 |
Matches the hand-checked answer exactly. The model never sees or writes a price.
How it works
Messy, multi-message customer text.
Proposes the order and the message's intent, quoting the chat for every fact.
Items, sizes and add-ons must exist on the menu; anything unknown becomes a question.
Totals, fees and change in integer cents.
States only verified facts, asks for what's missing.
The design rule: the AI only proposes. Anything with money or menu facts is decided by tested, deterministic code, so a model mistake turns into a clarifying question, not a wrong charge. A customer saying "I already paid" is recorded as a claim, never as a payment.
How I built it
The approach is distillation: a large, paid model (the "teacher") labels thousands of practice chats, and a small open model (the "student") is fine-tuned to copy it. Then you can run the small one yourself, cheaply and privately. Each step below was a measured experiment.
Build the exam first
I designed 3 fictional restaurants (a pizzeria, a burger place, a café) with real menu rules: sizes, add-ons, half-and-half pizzas, combos, delivery minimums. Then I had Claude write conversations from scenario cards and reviewed every expected answer by hand in an annotation tool I built (Preact + FastAPI):
-
Dev: 91 chats, 268 messages
for tuning prompts and code -
Fresh: 90 chats, 278 messages
written after the fixes, to check they generalize -
Test: 199 chats, sealed
locked by hash; opened once, at the very end
Which big model labels best per dollar?
12 settings across 4 providers (OpenAI, Anthropic, Google, DeepSeek), same prompt, same 35 chats. "Fully correct" means the entire order matches. Arrows show the gain from my code rules (e.g. filling in a default size), with no extra API calls.
| Model · reasoning setting | Cost / 1,000 chats | Fully correct (of 35) | Item F1 |
|---|---|---|---|
| DeepSeek Flash · none | $0.38 | 25 → 27 | 80.7 → 88.1% |
| GPT-6 Luna · none | $0.58 | 30 → 32 | 97.4% |
| GPT-6 Luna · low ✓ picked | $0.63 | 32 | 98.3% |
| GPT-6 Luna · medium | $0.74 | 29 → 30 | 90.1 → 93.7% |
| DeepSeek Flash · low | $0.84 | 33 | 95.5% |
| DeepSeek Flash · high | $0.88 | 29 → 32 | 84.1 → 91.6% |
| Claude Haiku 5.5 · thinking off, medium | $1.53 | 22 → 27 | 90.9 → 96.6% |
| Claude Haiku 5.5 · thinking off, low | $1.54 | 21 → 27 | 91.4 → 94.8% |
| Claude Haiku 5.5 · thinking low | $1.82 | 31 | 96.4% |
| Claude Haiku 5.5 · thinking medium | $1.90 | 33 | 100% |
| Gemini 3.1 Flash-Lite · minimal | $2.82 | 17 → 24 | 74.1 → 90.7% |
| Gemini 3.1 Flash-Lite · default | $2.94 | 22 → 28 | 78.2 → 94.5% |
- Picked GPT-6 Luna (low). It tied the most accurate setting in a 51-chat head-to-head at about a third of the cost. After two prompt fixes it got 90 of 91 dev orders fully correct.
- More reasoning wasn't better: the "medium" and "high" settings scored below "low".
- Code rules beat prompt tweaks where models had the facts but misapplied a rule (Gemini +6–7, Haiku +5–6 orders).
2,528 synthetic practice chats
Three cheaper models wrote practice conversations from generated scenario cards (so the style varies), and the teacher labeled them. Automatic checks dropped bad ones: invalid output, a business message stating a price, near-duplicates, labels quoting text that isn't in the chat. Independent AI auditors flagged doubtful labels for me to review; 47 labels were fixed by hand.
Training chats by writer (v2 data). The evaluation chats were never used as training input.
Can a small model do it out of the box? No.
Four small open models got the teacher's exact instructions on 20 chats, with no training. None produced a usable order: the 0.8B looped until it hit its length limit on every chat. Fine-tuning was required.
| Model | Size | Valid JSON | Usable labels | Median time |
|---|---|---|---|---|
| Qwen3.5-0.8B | 0.85B | 0/20 | 0/20 | 185 s |
| Qwen3.5-2B | 2.2B | 19/20 | 3/20 | 59 s |
| Qwen3-1.7B | 1.7B | 20/20 | 0/20 | 87 s |
| Gemma 4 E2B | 5.1B | 11/20 | 0/20 | 923 s |
Train, study the mistakes, fix the data, retrain
I trained three students with LoRA (PyTorch, Hugging Face transformers + PEFT) on Kaggle's free T4 GPUs, in resumable sessions under its 12-hour limit. Version 1 got the format right but missed patterns. So I sorted every dev mistake into categories, found that they came from thin training data (e.g. too few "actually, change that" chats), and wrote targeted data for those cases. Version 2, measured on the fresh chats:
Fully correct orders on the 90 fresh chats: grey = v1 data, teal = v2 data.
- Better data gave +15 to +18 orders for every model, all statistically significant (paired tests).
- The 2.6× bigger model wasn't better: the three v2 students don't differ significantly, so I picked the smallest: Qwen3.5-0.8B (69/90 fresh, 92% of messages understood; the teacher gets 90/91 on dev).
All six trained models, dev and fresh
| Student | Dev fully correct (91) | Fresh fully correct (90) | Fresh intents (278) | Fresh invalid answers |
|---|---|---|---|---|
| Qwen3.5-0.8B · v1 | 63 | 54 | 248 | 9 |
| Qwen3.5-2B · v1 | 59 | 51 | 248 | 10 |
| Qwen3.5-2B mixed · v1 | 65 | 52 | 252 | 5 |
| Qwen3.5-0.8B · v2 ✓ | 69 | 69 | 256 | 7 |
| Qwen3.5-2B · v2 | 69 | 69 | 263 | 3 |
| Qwen3.5-2B mixed · v2 | 73 | 70 | 257 | 8 |
Can a second model catch the small model's mistakes?
I showed three checkers 42 orders the student got wrong and 42 it got right (with the chat and menu) and asked "does this order match?". A checker that flags most wrong orders but few right ones could trigger a confirmation question only when needed.
| Checker | Wrong orders caught | False alarms on right orders |
|---|---|---|
| GPT-6 Luna (LLM) | 33 / 42 | 6 / 42 |
| Jev (decision model) | 28 / 42 | 2 / 42 |
| OpenAI Decisions | 25 / 42 | 4 / 42 |
The whole run cost under 3 cents. Building it also exposed a scoring gap, which I fixed.
Shrink it without losing accuracy
I merged the trained adapter into the model, converted it to GGUF and compressed (quantized) it with llama.cpp, then re-ran every evaluation chat through each version. Columns: fully correct orders on dev and fresh, typical seconds per answer on a T4 GPU and on a 4-core CPU, and peak GPU memory.
| Version | Size | Dev (91) | Fresh (90) | T4 GPU | GPU mem. | CPU |
|---|---|---|---|---|---|---|
| Original (16-bit) | 1.5 GB | 69 | 69 | 13.5 s | ||
| F16 GGUF | 1.52 GB | 69 | 69 | 3.9 s | 1.74 GB | |
| Q8_0 (8-bit) ✓ shipped | 0.81 GB | 69 | 69 | 2.6 s | 1.05 GB | 50 s |
| Q4_K_M (4-bit) | 0.53 GB | 66 | 66 | 2.3 s | 0.78 GB | 39 s |
- 8-bit gives identical orders to the original on both sets (not one chat differs), at half the size and 5× the speed.
- 4-bit saves 0.28 GB more but drops 3 orders per set (not statistically significant), so 8-bit ships.
- CPU-only is too slow for live chat as measured; most of the time goes to re-reading the long menu prompt. Caching that prompt and Apple Silicon are next.
Engineering highlights
A silent GPU failure, found by a guard
The first packaging run spent 11 hours "on the GPU" while actually running on the CPU: my script had replaced the system's library path, hiding the NVIDIA driver, and llama.cpp fell back without an error. I added stop rules (check the GPU is visible, check memory and speed after the first answer). The next attempt stopped itself in 4 minutes and logged the missing library. The fixed run took 2.2 hours.
Honest evaluation
Separate tuning, fresh and sealed test sets; paired statistical tests with confidence intervals rather than eyeballing; every number regenerated by code from saved run outputs. When a fresh chat led to a fix, its gain is labeled "used for fixes", not reported as a clean result.
Training under a 12-hour limit
Kaggle sessions stop at 12 hours, so training checkpoints itself, including its random-number state, and resumes in the next session. Along the way I fixed an upload that silently dropped subfolders and a resume bug in the random-number state.
Cost discipline
Every paid call was estimated first and logged afterwards from real token counts and verified prices. Total AI API spend so far is $6.63 against a $10 budget. All training and model evaluation ran on free GPUs.
Stack
About 17,000 lines of Python plus 6,800 lines of tests, 150+ commits since Oct 7, 2026.
What's next
- Run it on a Mac mini (Apple Silicon) with prompt caching for chat-speed replies.
- Benchmark small decision models as a message router.
- A live chat demo and a public model release.
- The final, one-time score on the sealed 199-chat test set.