contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
141 lines (140 loc) โข 6.26 kB
JavaScript
/**
* 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);