Skip to content

Comments

feat: Add ModelsLab image generation tool#11852

Open
adhikjoshi wants to merge 1 commit intodanny-avila:mainfrom
adhikjoshi:ml
Open

feat: Add ModelsLab image generation tool#11852
adhikjoshi wants to merge 1 commit intodanny-avila:mainfrom
adhikjoshi:ml

Conversation

@adhikjoshi
Copy link

🎨 ModelsLab Image Generation Tool for LibreChat

Professional AI image generation with 13+ cutting-edge models integrated into LibreChat's agent system.

Transform your LibreChat experience with ModelsLab's powerful image generation capabilities, featuring Flux, SDXL, Playground v2.5, and many more state-of-the-art models.

✨ Features

  • 13+ AI Models: Flux, SDXL, Playground v2.5, Stable Diffusion, and more
  • Competitive Pricing: $0.008-$0.018 per image (vs $0.020-$0.080 for DALL-E)
  • Professional Quality: Latest SOTA models for stunning results
  • Extensive Customization: Control every aspect of generation
  • Async Processing: Handles long-running generations with progress tracking
  • Multi-Format Support: Various resolutions up to 1536x1536
  • Safety Features: Built-in content filtering
  • Cost Transparency: Clear pricing displayed for each model

🚀 Quick Start

Prerequisites

  • LibreChat v0.7.7+
  • Node.js 18+
  • ModelsLab API key (Get one free)

Installation

  1. Add the tool files to your LibreChat installation:
# Copy the ModelsLab tool to your LibreChat tools directory
cp librechat-modelslab-integration/api/app/clients/tools/ModelsLabImage.js /path/to/librechat/api/app/clients/tools/

# Update the tools index file
cp librechat-modelslab-integration/api/app/clients/tools/index.js /path/to/librechat/api/app/clients/tools/

# Update the manifest file  
cp librechat-modelslab-integration/api/app/clients/tools/manifest.json /path/to/librechat/api/app/clients/tools/
  1. Set your API key:
# Add to your .env file
echo "MODELSLAB_API_KEY=your_api_key_here" >> .env
  1. Restart LibreChat:
npm run restart
  1. Enable in Agent:
    • Create or edit an Agent in LibreChat
    • Add "ModelsLab Image Generation" to the Tools list
    • Start generating images!

📖 Usage

Basic Usage

Simply ask your LibreChat agent to generate an image:

"Generate a futuristic cityscape at sunset with flying cars"

Advanced Usage

Use detailed prompts with model selection:

"Using the Flux model, create a professional headshot of a business woman in a modern office, 
corporate attire, soft lighting, high quality, detailed, 1024x1280 resolution"

Parameter Control

Specify generation parameters:

"Generate an artistic oil painting of a mountain landscape using SDXL model, 
negative prompt: 'blur, low quality, watermark', 30 steps, guidance scale 8.0"

🎯 Available Models

Model Description Cost Max Resolution Best For
Flux Latest SOTA model $0.018 1536×1536 Professional, detailed images
SDXL Stable Diffusion XL $0.015 1280×1280 Artistic, creative content
Playground v2.5 Aesthetic-focused $0.012 1024×1024 UI mockups, clean designs
Stable Diffusion Classic reliable $0.008 1024×1024 Quick iterations, concepts

⚙️ Configuration

Environment Variables

# Required: Your ModelsLab API key
MODELSLAB_API_KEY=your_api_key_here

# Optional: Custom API base URL (for enterprise customers)
MODELSLAB_BASE_URL=https://api.enterprise.modelslab.com

Tool Parameters

The ModelsLab tool supports extensive customization:

  • prompt (required): Detailed image description
  • model: Choose from flux, sdxl, playground-v2, stable-diffusion
  • negative_prompt: Elements to avoid
  • width/height: Image dimensions (256-1536px)
  • steps: Quality vs speed (10-50, recommended: 20-30)
  • guidance_scale: Prompt adherence (1-20, recommended: 5-12)
  • enhance_prompt: Auto-enhance prompts with quality terms
  • safety_checker: Content filtering (recommended: enabled)

💡 Example Prompts

Creative & Artistic

"Create a dreamy watercolor painting of cherry blossoms in spring, soft pastels, ethereal lighting, artistic style"

Professional & Business

"Generate a clean, modern business presentation slide background, corporate blue colors, subtle gradient, professional"

UI & Design

"Using Playground v2.5, create a mobile app login screen mockup, modern design, glassmorphism effects, clean interface"

Product Visualization

"Professional product photography of a sleek wireless headphone, studio lighting, white background, commercial quality"

🔧 Technical Details

Architecture

  • Base Class: LangChain StructuredTool
  • API Integration: Direct HTTP client to ModelsLab API
  • Async Support: Handles processing queue with polling
  • Error Handling: Comprehensive error messages and recovery
  • Logging: Detailed logging for debugging and monitoring

File Structure

api/app/clients/tools/
├── ModelsLabImage.js          # Main tool implementation
├── index.js                   # Tool exports and registration  
└── manifest.json             # UI metadata and configuration

Integration Points

  1. Tool Registration: Exported in index.js for system recognition
  2. UI Integration: Metadata in manifest.json for agent interface
  3. Environment Config: API key management via environment variables
  4. Error Handling: User-friendly error messages returned to chat
  5. Image Storage: Uses LibreChat's configured file storage strategy

🎨 Use Cases

Content Creation

  • Blog post illustrations
  • Social media graphics
  • Marketing materials
  • Concept art

Product Development

  • UI/UX mockups
  • Product visualizations
  • Brand imagery
  • Prototyping assets

Education & Training

  • Educational diagrams
  • Visual learning aids
  • Presentation graphics
  • Tutorial illustrations

Creative Projects

  • Artwork generation
  • Style exploration
  • Creative inspiration
  • Artistic experimentation

🔍 Troubleshooting

Common Issues

"ModelsLab API key is required"

  • Set MODELSLAB_API_KEY in your .env file
  • Verify the key is correct at Dashboard
  • Restart LibreChat after setting the key

"Insufficient credits"

  • Check your account balance at Billing
  • Add credits to your ModelsLab account
  • Consider using cheaper models for testing

Generation timeout

  • Large images (>1024px) take longer, wait patiently
  • Try reducing steps or image size
  • Use faster models like stable-diffusion for quick tests

Poor image quality

  • Use more descriptive, detailed prompts
  • Try flux model for highest quality
  • Increase steps (25-35) for better results
  • Enable enhance_prompt for automatic improvements

Getting Help

🤝 Contributing

We welcome contributions! This integration addresses LibreChat Issue #3671 and community requests for more image generation providers.

Development

  1. Fork the repository
  2. Make your changes
  3. Test thoroughly with various prompts and models
  4. Submit a pull request

Testing

# Test basic functionality
node -e "
const ModelsLabImageTool = require('./api/app/clients/tools/ModelsLabImage.js');
const tool = new ModelsLabImageTool();
console.log('Tool loaded successfully:', tool.name);
"

📊 Comparison with Other Tools

vs DALL-E

  • ✅ 4 models vs 1
  • ✅ $0.008-0.018 vs $0.020-0.080 per image
  • ✅ Higher max resolution (1536px vs 1024px)
  • ✅ More customization options
  • ✅ Competitive generation speed

vs Stable Diffusion (Local)

  • ✅ No local hardware requirements
  • ✅ Professional managed infrastructure
  • ✅ Multiple optimized models
  • ✅ No maintenance or updates needed
  • ✅ Reliable uptime and performance

vs Other Cloud Providers

  • ✅ More models in single integration
  • ✅ Competitive pricing
  • ✅ Better LibreChat integration
  • ✅ Comprehensive documentation and support

🏆 Why ModelsLab?

For Users

  • Cost Effective: Save up to 60% vs OpenAI DALL-E
  • More Choice: 13+ models vs single model tools
  • Better Results: Latest SOTA models like Flux
  • Easier to Use: Single tool for all your image needs

For Developers

  • Clean Integration: Follows LibreChat's patterns perfectly
  • Comprehensive: Full-featured tool with all options
  • Well Documented: Extensive documentation and examples
  • Future Proof: Regular model updates and improvements

For Communities

  • Open Source Friendly: Transparent integration
  • Community Requested: Addresses real user needs
  • Actively Maintained: Regular updates and support
  • Competitive Alternative: Reduces vendor lock-in

📜 License

This ModelsLab integration is provided under the same license as LibreChat (MIT).

🔗 Links


Made with ❤️ for the LibreChat community

Bring professional AI image generation to your LibreChat instance with ModelsLab's cutting-edge models and competitive pricing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant