contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
63 lines (62 loc) ⢠2.98 kB
JavaScript
import { ImageContextService } from '../services/ImageContextService.js';
async function testImageDetection() {
console.log('š¼ļø Testing Image Context Detection');
console.log('==================================\n');
const service = new ImageContextService(process.cwd());
// Test 1: Basic Detection
console.log('š Test 1: Image Reference Detection');
const testMessages = [
"analyze demo/test_ref_image.jpeg",
"what's in screenshot.png?",
"look at ./images/photo.jpg and tell me what you see",
"check this image: data/picture.webp",
"just a regular message without images",
"process the file data.txt"
];
for (const message of testMessages) {
const hasImages = service.hasImageReferences(message);
const references = service.extractImageReferences(message);
console.log(`š "${message}"`);
console.log(` Has images: ${hasImages ? 'ā
' : 'ā'}`);
if (references.length > 0) {
console.log(` References: ${references.join(', ')}`);
}
console.log('');
}
// Test 2: Image Processing
console.log('š Test 2: Image Processing');
try {
const images = await service.processImages(['demo/test_ref_image.jpeg']);
console.log(`ā
Successfully processed ${images.length} image(s)`);
if (images.length > 0) {
const img = images[0];
console.log(`š Image Details:`);
console.log(` Path: ${img.path}`);
console.log(` Size: ${img.size} bytes (${(img.size / 1024).toFixed(1)} KB)`);
console.log(` MIME Type: ${img.mimeType}`);
console.log(` Base64 length: ${img.base64Data.length} characters`);
console.log(` Description: ${img.description}`);
}
}
catch (error) {
console.log(`ā Image processing failed: ${error.message}`);
}
console.log('\nš Image Detection Tests Completed!');
console.log('\nš” Key Features:');
console.log(' ā
Automatic image detection in messages');
console.log(' ā
Support for JPG, PNG, GIF, WEBP, BMP, TIFF, SVG');
console.log(' ā
Base64 encoding for LLM context');
console.log(' ā
Path validation and security checks');
console.log(' ā
File size limits (20MB max)');
console.log('\nš§ Usage Examples:');
console.log(' ⢠"analyze screenshot.png"');
console.log(' ⢠"what\'s in ./images/photo.jpg?"');
console.log(' ⢠"check this image: demo/test.jpeg"');
console.log(' ⢠"compare image1.png and image2.jpg"');
console.log('\nšÆ Next Steps:');
console.log(' ⢠Configure Gemini API: contaigents configure');
console.log(' ⢠Use in chat: messages with image paths will automatically include images');
console.log(' ⢠Supported providers: Gemini (more coming soon)');
}
// Run the test
testImageDetection().catch(console.error);