Build a local AI feature
Keep the provider swappable
Define a small application interface so local and cloud implementations can change without leaking provider details through the product.
Do not let the entire application depend on Ollama response objects.
Define the operation your product needs:
type ActivitySummary = {
summary: string
confidence: 'low' | 'medium' | 'high'
}
type Summarizer = {
summarize(activity: Activity): Promise<ActivitySummary>
}
An Ollama implementation can call the local API. A cloud implementation can call a provider. A deterministic implementation can support tests and fallback behavior.
Normalize errors and output at the adapter boundary. The UI should not need to know whether a provider calls generated text message.content, output_text, or something else.
Swappable does not mean identical. Local and cloud models can differ in capabilities, privacy, latency, and cost. The interface preserves application structure while your evaluation decides whether each implementation is acceptable.
Lesson completed