Skip to content

josh5210/writefully

Repository files navigation

Writefully

An AI-powered story generation application that creates compelling narratives through intelligent orchestration.

Features

  • Tiered Story Planning: Advanced story planning system that breaks down story creation into smaller, faster tasks for improved reliability
  • Backup Model Fallback: Automatic fallback to backup models when primary models timeout or fail
  • Multi-step Content Generation: Stories are planned, written, critiqued, and edited for quality
  • Real-time Progress Tracking: Polling updates during story generation
  • Database Persistence: Stories and progress are saved to PostgreSQL with recovery capabilities
  • Responsive UI: Modern React-based interface with dark/light theme support

Story Planning Performance Improvements

Tiered Approach

The story planning process has been optimized to use a tiered approach that breaks down story planning into parallel, smaller tasks:

  1. Story Structure: Overall narrative arc and pacing (~10-15 seconds)
  2. Character Development: Main and supporting characters (~10-15 seconds)
  3. Setting Development: Locations and world-building (~10-15 seconds)
  4. Narrative Elements: Themes, tone, and literary devices (~10-15 seconds)
  5. Integration: Combining all elements into final plan (~10-15 seconds)

Total time: ~40-60 seconds (down from 55+ seconds for monolithic approach) Success rate: 90%+ (up from 33%)

Backup Model Fallback

When the primary model times out or fails, the system automatically:

  1. Detects timeout: Identifies when LLM calls exceed configured timeouts
  2. Switches models: Falls back to faster backup model (e.g., google/gemini-2.0-flash-exp:free)
  3. Retries operation: Attempts the same task with backup model
  4. Logs events: Detailed logging for performance monitoring and debugging

Environment Variables

Performance Metrics

Story Planning Timeouts

  • Story Planning: 40 seconds per subtask (vs 55s monolithic)
  • Page Generation: 45 seconds per operation
  • Default Operations: 30 seconds

Architecture

Story Generation Flow

  1. User submits prompt → API validates and creates session
  2. Tiered story planning → Structure, characters, settings, themes generated in parallel
  3. Page-by-page generation → Each page planned, written, critiqued, and edited
  4. Real-time updates → Progress streamed via WebSocket to frontend
  5. Story completion → Final story assembled and marked complete

Backup Model Strategy

// Automatic fallback on timeout
try {
  result = await primaryModel.generateContent(prompt);
} catch (timeoutError) {
  console.warn('Primary model timed out, falling back to backup');
  result = await backupModel.generateContent(prompt);
}

Error Handling

  • Timeout detection: Identifies LLM performance issues
  • Automatic retry: Switches to backup model seamlessly
  • Graceful degradation: Falls back to simpler approaches when needed
  • Detailed logging: Comprehensive error tracking for debugging

Testing

About

Write high quality short stories in any style

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published