UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

63 lines (62 loc) • 2.98 kB
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);