Week 1 · Lesson 01

Model adapter

One factory behind OpenAI-compatible chat completions. Skills never import a vendor SDK directly.

Time · ½–1 day LM Studio
Learn
  • baseURL + apiKey + model
  • OpenAI wire protocol as lingua franca (LM Studio, vLLM, cloud)
  • Timeouts, temperature, hard fail when unreachable
  • Why Anthropic-only model.js blocks local models
Build
  1. Single createModel() using OpenAI-compatible client (LangChain ChatOpenAI or official OpenAI SDK).
  2. Env example:
    OPENAI_BASE_URL=http://localhost:1234/v1
    OPENAI_API_KEY=lm-studio
    OPENAI_MODEL=your-local-model
  3. Tiny script: ping the model with one completion.
  4. Optional: same env vars pointed at cloud OpenAI — no code change.
Checkpoint

Same code talks to LM Studio and (optionally) cloud by changing env only. Missing server → clear error, not silent fake success.

Four notes
  • What problem does this layer solve?
  • What is allowed to call it?
  • What must it never do?
  • How do I observe and test it?