Week 1 · Lesson 01
Model adapter
One factory behind OpenAI-compatible chat completions. Skills never import a vendor SDK directly.
Learn
baseURL+apiKey+model- OpenAI wire protocol as lingua franca (LM Studio, vLLM, cloud)
- Timeouts, temperature, hard fail when unreachable
- Why Anthropic-only
model.jsblocks local models
Build
- Single
createModel()using OpenAI-compatible client (LangChainChatOpenAIor official OpenAI SDK). - Env example:
OPENAI_BASE_URL=http://localhost:1234/v1 OPENAI_API_KEY=lm-studio OPENAI_MODEL=your-local-model - Tiny script: ping the model with one completion.
- 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?