A comprehensive backup/fallback system has been implemented to provide graceful degradation when live AI models are unavailable due to API failures, network issues, or service outages. The system maintains a good user experience by seamlessly switching to pre-generated responses.
- Purpose: Loads pre-generated backup responses from JSON files
- Key Features:
loadBackupResponses(): Fetches backup responses for specific questionsfindMatchingBackupQuestion(): Intelligent keyword matching to find relevant backup responsesgetGenericFallbackResponse(): Provides persona-specific generic responses when no specific backup is available- Pre-defined demo questions with IDs for easy reference
- Purpose: Core backup service with automatic failure detection and fallback logic
- Key Features:
- Backup Modes:
disabled: No backup responsesauto: Automatically enables after consecutive failures (default: 2 failures)always: Always use backup responses (useful for demos)
- Failure Tracking: Records consecutive failures and successes
- Auto-Recovery: Automatically disables backup mode when LLM recovers
- State Management: Listeners for UI updates
- Streaming Support: Simulates streaming for backup responses with word-by-word delivery
- Status Reporting: Provides detailed status information for UI display
- Backup Modes:
- Changes:
- Added
personaIdtoChatRequesttype for backup response matching - Integrated backup service into
chatWithLLM()andchatWithLLMStreaming() - Added
extractUserQuestion()helper to extract user's question from message history - Automatic failure recording and success tracking
- Seamless fallback to backup responses when LLM fails
- Pre-check for backup mode before attempting LLM calls
- Added
- Changes:
- Added backup mode state (
backupMode,backupStatus) - Imported backup service functions
- Added backup state listener for real-time status updates
- Updated all
chatWithLLM()andchatWithLLMStreaming()calls to includepersonaId - Added backup mode settings to localStorage persistence
- UI Controls (in Settings):
- Backup mode selector (disabled/auto/always)
- Real-time status display with visual indicators
- Contextual help text explaining each mode
- Added backup mode state (
- Purpose: Stores pre-generated backup responses as JSON files
- Files:
q1-technical-bottlenecks.jsonq2-model-selection.jsonq3-data-sovereignty.jsonq4-community-model.jsonq5-debugging-approach.jsonq6-future-architecture.json
- Structure: Each file contains a question and responses from all personas (maya, otto, sarah, marcus, jessica)
- When an LLM API call fails,
recordFailure()is called - The failure counter increments
- If in
automode and failures reach threshold (default: 2), backup mode activates - When an LLM call succeeds,
recordSuccess()resets the counter and deactivates backup mode
- Check Backup Mode: Before making LLM call, check if backup mode is active
- Extract Question: Get the user's question from message history
- Find Match: Use keyword matching to find relevant pre-generated response
- Fallback Chain:
- Try to find matching pre-generated response
- If not found, use persona-specific generic response
- If all else fails, use ultimate fallback message
- Backup responses are split into words
- Words are delivered progressively with small delays (30ms default)
- Provides natural streaming experience matching live LLM behavior
- Works seamlessly with TTS and UI updates
The backup system is fully integrated with the existing persona system:
- Each backup response is persona-specific
- Generic fallbacks reflect each persona's voice and expertise
- Persona IDs are passed through the entire call chain
- Works with both streaming and non-streaming modes
Located in Settings → General → Backup/Fallback System:
- Mode Selector: Dropdown to choose backup mode
- Status Display: Real-time status with color-coded background
- Gray: Ready/Monitoring
- Yellow: Active (using backups)
- Help Text: Context-sensitive explanations for each mode
- "Backup mode: Ready" - Auto mode, no failures
- "Backup mode: Monitoring (1/2 failures)" - Tracking failures
- "Backup mode: Active (2 failures detected)" - Using backups
- "Backup mode: Always active" - Always mode enabled
- "Backup mode: Disabled" - No backup support
- Set backup mode to "Auto"
- Stop your LLM service (e.g., Ollama)
- Ask a question
- After 2 failed attempts, backup mode activates
- Subsequent questions use backup responses
- Restart LLM service
- Next successful response deactivates backup mode
- Set backup mode to "Always"
- Ask questions matching demo topics (e.g., "What are the technical bottlenecks?")
- Receive pre-generated responses immediately
- Useful for demos when LLM is unavailable
- Set backup mode to "Always"
- Ask a question that doesn't match any demo questions
- Receive persona-specific generic response
The system includes pre-generated responses for these topics:
- Technical Bottlenecks - LLM+GeoAI integration challenges
- Model Selection - Choosing models for LIDAR processing
- Data Sovereignty - Architecture for data governance
- Community Model - PostGIS LLM development
- Debugging Approach - Complex geometry processing
- Future Architecture - Evolution of geospatial AI systems
type BackupMode = 'disabled' | 'auto' | 'always';
interface BackupConfig {
mode: BackupMode;
enabled: boolean;
consecutiveFailures: number;
autoEnableThreshold: number; // Default: 2
}- Failure Threshold: Modify
autoEnableThresholdinbackup.ts - Streaming Delay: Adjust
delayMsparameter instreamBackupResponse() - Add New Responses: Create new JSON files in
public/demo-backup/ - Update Matching: Modify
findMatchingBackupQuestion()logic
- Reliability: Application remains functional even when LLM services fail
- User Experience: Seamless fallback without error messages
- Demo Mode: Perfect for presentations when LLM is unavailable
- Graceful Degradation: Maintains conversation flow with relevant responses
- Automatic Recovery: Returns to live LLM when service recovers
- Transparency: Clear status indicators show when backup mode is active
Potential improvements:
- More Backup Responses: Expand the library of pre-generated responses
- Better Matching: Use semantic similarity instead of keyword matching
- Response Caching: Cache recent LLM responses as backups
- Partial Failures: Handle individual persona failures differently
- Analytics: Track backup usage patterns
- Custom Responses: Allow users to add their own backup responses
- Create a new JSON file in
public/demo-backup/ - Follow the existing structure:
{
"question": "Your question here",
"responses": {
"maya": { "content": "...", "timestamp": "..." },
"otto": { "content": "...", "timestamp": "..." },
"sarah": { "content": "...", "timestamp": "..." },
"marcus": { "content": "...", "timestamp": "..." },
"jessica": { "content": "...", "timestamp": "..." }
}
}- Add the question to
DEMO_QUESTIONSarray inbackup-loader.ts - Update matching logic in
findMatchingBackupQuestion()if needed
Edit the genericResponses object in getGenericFallbackResponse() in backup-loader.ts
The backup/fallback system provides a robust safety net for the application, ensuring users always receive meaningful responses even when AI services are unavailable. The system is transparent, configurable, and integrates seamlessly with existing features including streaming, TTS, and the persona system.