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
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
- Add the node to your flow from the function category
- Configure OpenAI API key in the node settings
- Select a theme (madness-dark, madness-light, madness-neon)
- 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 generationmsg.topic
(string): Optional topic (passed through)
Output
msg.template
(string): Generated HTML templatemsg._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
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
- Issues: GitHub Issues
- Documentation: Node-RED Flow Library
- Examples: See the
examples/
directory
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