node-red-contrib-mad-template-ai 1.0.1

A Node-RED node that generates dynamic HTML templates using OpenAI LLM based on input data, with intelligent caching and MadnessInteractive theming

npm install node-red-contrib-mad-template-ai

node-red-contrib-mad-template-ai

A Node-RED node that generates dynamic HTML templates using OpenAI's GPT models based on input data, with intelligent caching and MadnessInteractive theming.

Features

๐Ÿค– AI-Powered Template Generation

  • Generate HTML templates dynamically using OpenAI GPT models
  • Support for GPT-3.5 Turbo, GPT-4, and other OpenAI models
  • Configurable creativity with temperature settings

๐ŸŽจ MadnessInteractive Theming

  • Three built-in themes: Dark (Cyberpunk), Light (Modern), Neon (Vibrant)
  • Automatic CSS injection and theming
  • Responsive design with mobile support

โšก Performance Optimized

  • Intelligent caching to reduce API calls and costs
  • Hash-based cache keys for efficient storage
  • Configurable cache duration and strategies

๐Ÿ›ก๏ธ Robust Error Handling

  • Automatic retry with exponential backoff
  • Fallback templates when AI generation fails
  • Comprehensive error logging and status indicators

๐Ÿš€ Easy Configuration

  • User-friendly configuration interface
  • Theme-based system prompts
  • Boot-time template generation support

Installation

npm install node-red-contrib-mad-template-ai

Or install directly through the Node-RED palette manager.

Quick Start

  1. Add the node to your flow from the function category
  2. Configure OpenAI API key in the node settings
  3. Select a theme (madness-dark, madness-light, madness-neon)
  4. Connect input data and deploy!

Basic Example

// Input message
msg.payload = {
    title: "Sales Dashboard",
    stats: {
        revenue: 125000,
        orders: 342,
        customers: 89
    },
    charts: ["sales", "traffic"]
};
// Output: Beautiful HTML dashboard generated by AI

Configuration

OpenAI Settings

  • API Key: Your OpenAI API key (stored securely)
  • Model: Choose between GPT-3.5 and GPT-4 variants
  • Temperature: Controls creativity (0 = deterministic, 2 = very creative)
  • Max Tokens: Maximum length of generated response

Template Settings

  • Theme: Built-in MadnessInteractive themes
  • System Prompt: Custom instructions for AI (optional)
  • Template Data: Message property containing data for generation
  • Output Format: String or parsed object output

Performance Settings

  • Enable Caching: Cache identical requests (recommended)
  • Cache Duration: How long to cache results (seconds)
  • Retry Attempts: Number of retry attempts on API failure
  • Timeout: OpenAI API timeout (milliseconds)

Themes

Madness Dark (Cyberpunk)

Perfect for dashboards, monitoring interfaces, and futuristic applications.

  • Dark backgrounds with neon accents
  • Glowing text effects and borders
  • Green, pink, and blue color scheme

Madness Light (Modern)

Clean and professional for business applications and reports.

  • White backgrounds with subtle grays
  • Professional blue, red, and green accents
  • Clean typography and spacing

Madness Neon (Vibrant)

High-energy theme for gaming, entertainment, and dynamic content.

  • Deep space backgrounds with intense colors
  • Multiple neon colors with glowing effects
  • Animated elements and visual effects

Examples

Dashboard Generation

{
    "title": "System Dashboard",
    "stats": {
        "users": 1234,
        "orders": 567,
        "revenue": 89012
    },
    "charts": ["sales", "traffic"],
    "alerts": [
        {"type": "warning", "message": "High CPU usage"}
    ]
}

Report Templates

{
    "reportType": "monthly",
    "period": "January 2024",
    "data": [
        {"month": "Jan", "sales": 1000},
        {"month": "Feb", "sales": 1200}
    ],
    "summary": "Sales increased 20% this quarter"
}

Data Visualization

{
    "chartType": "bar",
    "title": "Performance Metrics",
    "datasets": [
        {"label": "CPU", "value": 65, "max": 100},
        {"label": "Memory", "value": 78, "max": 100},
        {"label": "Disk", "value": 23, "max": 100}
    ]
}

API Reference

Input

  • msg.payload (object): Data for template generation
  • msg.topic (string): Optional topic (passed through)

Output

  • msg.template (string): Generated HTML template
  • msg._madTemplateAI (object): Generation metadata

Metadata Object

{
    "cached": false,           // Whether result came from cache
    "model": "gpt-3.5-turbo", // OpenAI model used
    "theme": "madness-dark",   // Applied theme
    "timestamp": 1642678800000, // Generation timestamp
    "inputHash": "abc123..."    // Cache key hash
}

Cost Optimization

The node includes several features to minimize OpenAI API costs:

  • Smart Caching: Identical requests are cached to avoid duplicate API calls
  • Efficient Hashing: Input data is hashed for optimal cache key generation
  • Fallback Templates: Error scenarios use local templates instead of retrying
  • Configurable Models: Choose cost-effective models for your use case

Error Handling

The node gracefully handles various error scenarios:

  • API Key Issues: Clear validation and error messages
  • Network Problems: Automatic retry with exponential backoff
  • Rate Limiting: Respects OpenAI API limits with proper error handling
  • Invalid Responses: Falls back to error templates with user data

Development

Project Structure

node-red-contrib-mad-template-ai/
โ”œโ”€โ”€ package.json              # npm configuration
โ”œโ”€โ”€ mad-template-ai.js         # Main node implementation
โ”œโ”€โ”€ mad-template-ai.html       # Configuration UI & help
โ”œโ”€โ”€ examples/                  # Example flows
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ system-prompts/        # Theme-based prompts
โ”‚   โ””โ”€โ”€ fallbacks/            # Error fallback templates
โ”œโ”€โ”€ themes/                   # CSS theme files
โ””โ”€โ”€ README.md                 # This file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

Changelog

v1.0.1

  • Fixed repository URLs to point to MadnessEngineering organization
  • Updated GitHub links and issue tracking

v1.0.0

  • Initial release
  • OpenAI GPT integration
  • Three MadnessInteractive themes
  • Intelligent caching system
  • Comprehensive error handling
  • Example flows and documentation

Built with โค๏ธ for the MadnessInteractive ecosystem by D. Edens

Node Info

Version: 1.0.1
Updated 1 week, 6 days ago
License: MIT
Rating: not yet rated

Categories

Actions

Downloads

0 in the last week

Nodes

  • mad-template-ai

Keywords

  • node-red
  • ai
  • openai
  • template
  • html
  • dynamic
  • generation
  • llm
  • dashboard
  • madness
  • interactive
  • gpt
  • caching

Maintainers