UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

141 lines (140 loc) โ€ข 6.26 kB
#!/usr/bin/env node /** * Test script for Image Reference Generation Tool * Tests the new reference image capabilities of ImageGenerationTool */ import { ImageGenerationTool } from '../services/tools/ImageGenerationTool.js'; import fs from 'fs/promises'; async function createTestReferenceImage() { // Create a simple test image (1x1 pixel PNG) for testing const testImagePath = 'test-reference-image.png'; // Simple 1x1 pixel PNG in base64 const pngBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChAI9jU77zgAAAABJRU5ErkJggg=='; const pngBuffer = Buffer.from(pngBase64, 'base64'); await fs.writeFile(testImagePath, pngBuffer); console.log(`โœ… Created test reference image: ${testImagePath}`); return testImagePath; } async function testImageReferenceGeneration() { console.log('๐Ÿงช Testing Image Reference Generation Tool...\n'); try { // Create test reference image const referenceImagePath = await createTestReferenceImage(); // Initialize tool const tool = new ImageGenerationTool(process.cwd()); console.log('๐Ÿ“‹ Tool Information:'); console.log(`Name: ${tool.getName()}`); console.log(`Description: ${tool.getDescription()}`); console.log('\n๐Ÿ“ Parameters:'); tool.getParameters().forEach(param => { console.log(` - ${param.name} (${param.type}): ${param.description}`); }); // Test 1: Basic reference image generation console.log('\n๐ŸŽจ Test 1: Basic Reference Image Generation'); const result1 = await tool.execute({ prompt: 'Transform this image into a beautiful watercolor painting with soft, flowing brushstrokes and vibrant colors', output_path: 'test-output-reference.png', provider: 'gemini', reference_images: [referenceImagePath], reference_strength: 0.8, reference_mode: 'style' }); if (result1.success) { console.log('โœ… Reference image generation successful!'); console.log('๐Ÿ“Š Result data:', JSON.stringify(result1.data, null, 2)); console.log('๐Ÿ’ฌ Message:', result1.message); } else { console.log('โŒ Reference image generation failed:', result1.error); } // Test 2: Multiple reference modes console.log('\n๐ŸŽจ Test 2: Different Reference Modes'); const modes = ['style', 'composition', 'color', 'mixed']; for (const mode of modes) { console.log(`\n Testing reference_mode: ${mode}`); const result = await tool.execute({ prompt: `Create an artistic interpretation using ${mode} guidance from the reference image`, output_path: `test-output-${mode}.png`, provider: 'gemini', reference_images: [referenceImagePath], reference_strength: 0.7, reference_mode: mode }); if (result.success) { console.log(` โœ… ${mode} mode successful`); } else { console.log(` โŒ ${mode} mode failed: ${result.error}`); } } // Test 3: Parameter validation console.log('\n๐Ÿ” Test 3: Parameter Validation'); // Test invalid reference strength const invalidStrengthResult = await tool.execute({ prompt: 'Test prompt', output_path: 'test-invalid.png', reference_images: [referenceImagePath], reference_strength: 1.5 // Invalid: > 1.0 }); if (!invalidStrengthResult.success) { console.log('โœ… Invalid reference_strength correctly rejected:', invalidStrengthResult.error); } else { console.log('โŒ Invalid reference_strength should have been rejected'); } // Test invalid reference mode const invalidModeResult = await tool.execute({ prompt: 'Test prompt', output_path: 'test-invalid.png', reference_images: [referenceImagePath], reference_mode: 'invalid_mode' }); if (!invalidModeResult.success) { console.log('โœ… Invalid reference_mode correctly rejected:', invalidModeResult.error); } else { console.log('โŒ Invalid reference_mode should have been rejected'); } // Test 4: Non-existent reference image console.log('\n๐Ÿ” Test 4: Non-existent Reference Image'); const nonExistentResult = await tool.execute({ prompt: 'Test prompt', output_path: 'test-nonexistent.png', reference_images: ['non-existent-image.png'] }); if (!nonExistentResult.success) { console.log('โœ… Non-existent reference image correctly rejected:', nonExistentResult.error); } else { console.log('โŒ Non-existent reference image should have been rejected'); } // Test 5: Too many reference images console.log('\n๐Ÿ” Test 5: Too Many Reference Images'); const tooManyResult = await tool.execute({ prompt: 'Test prompt', output_path: 'test-toomany.png', reference_images: [referenceImagePath, referenceImagePath, referenceImagePath, referenceImagePath] // 4 images, max is 3 }); if (!tooManyResult.success) { console.log('โœ… Too many reference images correctly rejected:', tooManyResult.error); } else { console.log('โŒ Too many reference images should have been rejected'); } // Cleanup console.log('\n๐Ÿงน Cleaning up test files...'); try { await fs.unlink(referenceImagePath); console.log('โœ… Test reference image cleaned up'); } catch (error) { console.log('โš ๏ธ Could not clean up test reference image:', error); } console.log('\n๐ŸŽ‰ Image Reference Generation Tool tests completed!'); } catch (error) { console.error('โŒ Test failed with error:', error); } } // Run the test testImageReferenceGeneration().catch(console.error);