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.

77%
orders fully correct on 90 new chats (69/90), every item, size, time and payment
92%
of 278 customer messages understood correctly (order, question, complaint…)
0.81 GB
final model file, 2.6 s per answer on a T4 GPU (5× faster than before packaging)
$6.63
total AI API spend for the whole project so far; training ran free on Kaggle GPUs

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.

1 · The chat (Morning Crumb Café)
CAN I GET A MEDIUM DRIP COFFE AND A BLUBERRY MUFFIN
PICKUP AT 8:45 FOR ANA
ACTUALLY MAKE IT 2 MUFFINS
CARD
2 · The model's proposal
  • 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
3 · Checked and priced by code
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

Chat

Messy, multi-message customer text.

Small model

Proposes the order and the message's intent, quoting the chat for every fact.

Code checks

Items, sizes and add-ons must exist on the menu; anything unknown becomes a question.

Pricing engine

Totals, fees and change in integer cents.

Reply

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.

Step 1 · Test data before anything else

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
Step 2 · Teacher bake-off

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.3825 → 2780.7 → 88.1%
GPT-6 Luna · none$0.5830 → 3297.4%
GPT-6 Luna · low ✓ picked$0.633298.3%
GPT-6 Luna · medium$0.7429 → 3090.1 → 93.7%
DeepSeek Flash · low$0.843395.5%
DeepSeek Flash · high$0.8829 → 3284.1 → 91.6%
Claude Haiku 5.5 · thinking off, medium$1.5322 → 2790.9 → 96.6%
Claude Haiku 5.5 · thinking off, low$1.5421 → 2791.4 → 94.8%
Claude Haiku 5.5 · thinking low$1.823196.4%
Claude Haiku 5.5 · thinking medium$1.9033100%
Gemini 3.1 Flash-Lite · minimal$2.8217 → 2474.1 → 90.7%
Gemini 3.1 Flash-Lite · default$2.9422 → 2878.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).
Step 3 · Training data

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.

DeepSeek Flash
1,662
Gemini Flash-Lite
419
Claude Haiku
329
Targeted hard cases
118

Training chats by writer (v2 data). The evaluation chats were never used as training input.

Step 4 · Student bake-off

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.

ModelSizeValid JSONUsable labelsMedian time
Qwen3.5-0.8B0.85B0/200/20185 s
Qwen3.5-2B2.2B19/203/2059 s
Qwen3-1.7B1.7B20/200/2087 s
Gemma 4 E2B5.1B11/200/20923 s
Step 5 · Fine-tuning (LoRA) on free GPUs

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:

Qwen3.5-0.8B (picked)54 → 69 / 90
Qwen3.5-2B51 → 69 / 90
Qwen3.5-2B, mixed menus52 → 70 / 90

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
StudentDev fully correct (91)Fresh fully correct (90)Fresh intents (278)Fresh invalid answers
Qwen3.5-0.8B · v163542489
Qwen3.5-2B · v1595124810
Qwen3.5-2B mixed · v165522525
Qwen3.5-0.8B · v2 ✓69692567
Qwen3.5-2B · v269692633
Qwen3.5-2B mixed · v273702578
Step 6 · A safety net

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.

CheckerWrong orders caughtFalse alarms on right orders
GPT-6 Luna (LLM)33 / 426 / 42
Jev (decision model)28 / 422 / 42
OpenAI Decisions25 / 424 / 42

The whole run cost under 3 cents. Building it also exposed a scoring gap, which I fixed.

Step 7 · Packaging for deployment

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.

VersionSizeDev (91)Fresh (90)T4 GPUGPU mem.CPU
Original (16-bit)1.5 GB696913.5 s
F16 GGUF1.52 GB69693.9 s1.74 GB
Q8_0 (8-bit) ✓ shipped0.81 GB69692.6 s1.05 GB50 s
Q4_K_M (4-bit)0.53 GB66662.3 s0.78 GB39 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

Python 3.12 Pydantic v2 contracts PyTorch Hugging Face transformers + PEFT (LoRA) llama.cpp / GGUF Kaggle T4 GPUs OpenAI · Anthropic · Gemini · DeepSeek APIs FastAPI + Preact (annotation tool) pytest: 547 tests

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.