How instruct-rb/instruct works
Main Components
a) Core Components:
• Prompt Management System
• Generation System
• Middleware Chain
• LLM Provider Adapters
• Rails Integration Layer
b) External Components:
• OpenAI API
• Anthropic API
• Rails Framework (optional integration)
┌─ Application Layer ─────────────────────────────────────┐
• User Code / Rails Applications │
• Public API Layer ──────────────────────────────────── │
• Core Processing Layer ────────────────────────────────│
• ┌─ Prompt System ─┐ ┌─ Generation System ─┐ │
• ERB Compiler │ │ - Completion Request │ │
• Safety Marking│ │ - Response Handling │ │
• ┘ └──────────────────────┘ │
• Middleware Chain ───────────────────────────────────┐ │
• Chat Completion → Chomp → Custom Middleware → ... │ │
• Provider Adapters ─────────────────────────────────┐ │
• OpenAI Adapter Anthropic Adapter │ │
• ┘
• ▼ ▼
OpenAI API Anthropic API
Key Elements to Highlight
a) Data Flow:
• Blue: Core components
• Green: External services
• Yellow: Middleware components
• Purple: Integration points
• Gray: Optional components
Important Architectural Patterns
a) Middleware Chain Pattern:
• How middleware components can be chained
• Order of middleware execution
• How middleware can transform both requests and responses
b) Provider Adapter Pattern:
• How different LLM providers are abstracted
• Standardized interface they implement
• Provider-specific middleware
c) Rails Integration:
• Optional Rails components
• Serialization paths
• ActiveJob integration points
Additional Details
• The different types of components
• Common middleware configurations
Implementation Notes
• The separation between prompt management and generation
• The flexibility of the middleware system
• The safety mechanisms for prompt handling
• The streaming capability throughout the stack
Specific Features to Highlight
• ERB-based prompt templating
• Safe/unsafe content handling
• Completion capture mechanism
• Streaming support
• Serialization capabilities
• Rails integration points