Build a local AI feature
Define the feature boundary
Add local AI as one narrow transformation with explicit input, output, timeout, and fallback behavior.
We will build a local activity summarizer.
Its input is factual application data:
const activity = {
focusMinutes: 52,
completedTasks: 3,
interrupted: false,
}
Its output is one sentence plus a confidence label:
{
summary: 'You focused for 52 minutes and completed 3 tasks.',
confidence: 'high',
}
The original activity record remains the source of truth. The generated sentence is a convenience.
Define failure before writing the request. If Ollama is missing, the model is unavailable, the request times out, or the response fails validation, the application will create a deterministic sentence from the original fields.
This boundary keeps the product useful without AI. It also gives us an exact contract to test.
Lesson completed