Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a new Image Generator tool that creates high-quality educational images from text prompts. The tool leverages Black Forest Labs' Flux 1.1 Pro API for image generation and includes Google Cloud Storage integration for persistent image storage. It features educational context enhancement, content type detection and subsequent prompt enhancement, and safety filtering to ensure generated images are high quality and appropriate for educational use.
I have included a Loom video walkthrough.
Related Issue
N/A
Type of Change
Please select the type(s) of change that apply and delete those that do not.
Proposed Solution
The Image Generator tool is designed to create educational images with the following key components:
How to Test
Test Configuration:
Use the FastAPI Swagger UI at http://localhost:8000/docs to test the /submit-tool endpoint with the following JSON:
Expected Outcome:
The response should include:
image_b64
field containing a base64-encoded imageprompt_used
field showing the enhanced prompteducational_context
field with "astronomy for middle school level"safety_applied
field set totrue
Example response:
If GCP storage is configured, the response will also include a
gcp_url
field with a public URL to the stored image.Test Configuration:
Expected Outcome:
The response should show that the prompt was enhanced with the appropriate educational context:
prompt_used
field should include "educational context: biology for high school level"Try another example with a different subject and grade level:
The response should show a simpler, more elementary-appropriate enhancement in the
prompt_used
field.Test Configuration:
Expected Outcome:
The system should reject the unsafe content with an error response:
The logs should show:
Test Configuration:
Expected Outcome:
The system should return an error indicating that the prompt is required.
Unit Tests
The implementation includes comprehensive test coverage:
Core Functionality Tests:
test_executor
: Tests the main executor functiontest_executor_without_gcp
: Tests behavior without GCP configurationtest_executor_missing_inputs
: Tests error handling for missing inputsImage Generation Tests:
test_generate_image_with_api_key
: Tests basic image generationtest_generate_image_with_gcp_storage
: Tests GCP storage integrationtest_generate_image_development_mode
: Tests fallback behavior without API keyEducational Enhancement Tests:
test_generate_educational_image
: Tests the full educational pipelinetest_enhance_prompt_with_educational_context
: Tests context enhancementtest_detect_content_type
: Tests content type detectionSafety Tests:
test_check_prompt_safety
: Tests safety filteringtest_generate_educational_image_unsafe
: Tests rejection of unsafe contentGCP Integration Tests:
test_upload_to_gcp_bucket
: Tests GCP upload functionalitytest_generate_educational_image_without_gcp
: Tests behavior without GCPDocumentation Updates
Indicate whether documentation needs to be updated due to this PR.
The README.md written in the PR includes comprehensive documentation covering:
Checklist
Additional Information