Build a local AI feature
Add a deterministic fallback
Preserve the application value when local inference is unavailable by generating a truthful result from source data.
The fallback should not pretend to be another AI model.
Build the sentence directly from fields the application already trusts:
function fallbackSummary(activity) {
return {
summary: `You focused for ${activity.focusMinutes} minutes and completed ${activity.completedTasks} tasks.`,
confidence: 'high',
}
}
Call the model inside a narrow wrapper. Return the validated model result on success and the deterministic result on expected local failures.
Do not hide programming errors. A misspelled variable or invalid application state should fail a test, not quietly look like an Ollama outage.
The interface can label generated text when that distinction matters. It does not need to interrupt the user every time the optional enhancement falls back.
This pattern is useful for summaries, labels, suggestions, and other features where the original data remains valuable by itself.
Lesson completed