Automated Banner Image Generation for Workflow Prompts for AI-Labs

Summary

Automated the generation and injection of banner images for all Markdown prompt files in /content/lost-in-public/prompts/workflow using a custom Python script and the Recraft API.

Why Care

This workflow ensures every prompt has a visually relevant, AI-generated banner image, improving the visual quality and consistency of documentation. It also enforces security and maintainability by using environment variables and externalized style configuration.

Implementation

Changes Made

  • Set up Python virtual environment in the a-labs submodule.
  • Created and configured the Recraft API key and other parameters necessary for successful AI image generation.
  • Selected five sample images that allowed us to develop our own "style" for the Recraft API.
  • Updated and ran ai-labs/recraft/generate-banner-images-recraft.py to process all prompts for the prompt library.
  • Script loads a custom style from a JSON file and securely loads the Recraft API token from environment variables.
  • Robust error handling for missing tokens or invalid styles.

Technical Details

  • The script uses the image_prompt field to generate images via the Recraft API and injects the returned URL into the banner_image field.
  • All API tokens are loaded from environment variables; no sensitive data is hardcoded.
  • Custom style configuration is stored in a JSON file for reproducibility.
  • Aggressive commenting and DRY principles followed throughout the script.

Integration Points

  • All prompt files in /content/lost-in-public/prompts/ now include a banner_image field.
  • No breaking changes to existing metadata or content structure.
  • Future prompt/image generation workflows should build on this pattern.

Documentation

  • See /ai-labs/recraft/generate-banner-images-recraft.py for script logic and usage.
  • used the Ask Generative AI model to generate a Style to get GPT 4.1 to generate the image_prompt values.
  • All changes follow the changelog entry guidelines in /content/lost-in-public/prompts/workflow/Write-a-Code-Changelog-Entry.md.
  • The script workflow is now fully recursive and supports robust error handling for missing tokens or invalid styles.

Content & Metadata Enhancements

  • YAML Frontmatter Updates:
    • Added or updated banner_image fields in all processed workflow prompt files, ensuring each has a visually relevant, AI-generated image.
    • Maintained strict preservation of all existing metadata and formatting.

Security & Configuration

  • Environment Variables:
    • All API tokens are securely loaded from environment variables; no sensitive data is hardcoded.
    • Custom style configuration is externalized to a JSON file for easy updates and reproducibility.

Code Quality & Documentation

  • Aggressive Commenting and DRY Principles:
    • Script and workflow changes are thoroughly commented, following the project’s aggressive documentation standards.
    • Modular, single-source-of-truth approach for style and token management.

Next Steps

  • Review generated banner images for creative quality and relevance.
  • Continue to iterate on prompt and image generation workflows as needed.