On-device AI with Apple foundation models
File: apple-system-model.lisp
Recent macOS versions ship with Apple’s on-device foundation model, which scripts reach through the fm command-line tool. This nine-line program is the shortest LLM client in the book: no API key, no network, no bill.
The code
1 ;; sbcl --script apple-system-model.lisp (macOS Apple Foundation Model)
2 (require :asdf)
3
4 (defun apple-fm (prompt)
5 (string-trim '(#\Space #\Newline #\Return)
6 (uiop:run-program
7 (list "fm" "respond" "--no-stream" prompt)
8 :output :string)))
9
10 (print (apple-fm "what is 1 + 10?"))
How it works
(require :asdf)loads UIOP. This book usesuiop:run-programthroughout to run external commands and capture their output.apple-fmrunsfm respond --no-stream <prompt>and captures standard output as a string with:output :string. The--no-streamflag makesfmprint the whole reply at once instead of streaming tokens.string-trimremoves the whitespace thatfmadds around the reply.
Running it
You need macOS with Apple Intelligence turned on and the fm license accepted (sudo fm license). Then:
1 $ sbcl --script apple-system-model.lisp
The program prints the model’s reply as a Lisp string. Actual output (the wording varies between runs):
1 "11"
Using it
The model runs on your Mac, so use it for prompts that should not leave the machine: summarizing private notes, classifying local documents, or adding small language tasks to Lisp scripts. The trade-offs: the model is small and weaker than hosted models, and this interface gives no control over temperature or system prompts. For harder tasks, see the Gemini and Ollama chapters that follow.