UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

124 lines (123 loc) โ€ข 5.56 kB
#!/usr/bin/env node /** * Test Creative Prompt Generation * * This script tests that the agent will create more creative prompts * by simulating a chat interaction with image generation requests */ import { ChatService } from '../services/chatService.js'; import fs from 'fs/promises'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Test configuration const TEST_OUTPUT_DIR = path.join(__dirname, 'creative_prompt_test'); class CreativePromptTest { constructor() { this.chatService = new ChatService(TEST_OUTPUT_DIR, true); // Enable debug to see prompts } async setup() { console.log('๐ŸŽจ Setting up Creative Prompt Generation Test'); console.log('='.repeat(55)); // Create test output directory await fs.mkdir(TEST_OUTPUT_DIR, { recursive: true }); console.log(`๐Ÿ“ Test directory created: ${TEST_OUTPUT_DIR}`); console.log(''); } async testSimpleToCreativePrompt() { console.log('โœจ Test: Simple Request โ†’ Creative Prompt Transformation'); console.log('-'.repeat(55)); // Test simple user requests that should be transformed into creative prompts const testCases = [ { userRequest: "Generate an image of a cat", expectedElements: ["detailed description", "artistic style", "lighting", "composition"] }, { userRequest: "Create a picture of a sunset", expectedElements: ["atmospheric details", "color palette", "mood", "photographic style"] }, { userRequest: "Make an image of a robot", expectedElements: ["specific design details", "materials", "environment", "artistic technique"] } ]; for (let i = 0; i < testCases.length; i++) { const testCase = testCases[i]; console.log(`\n๐Ÿงช Test Case ${i + 1}: "${testCase.userRequest}"`); try { // Create a chat session const session = this.chatService.createSession({ provider: 'google', model: 'gemini-2.5-flash' }); // Send the simple request console.log('๐Ÿ‘ค User request:', testCase.userRequest); const response = await this.chatService.sendMessage(session.id, testCase.userRequest); console.log('๐Ÿค– Agent response:'); console.log(` ${response.content.slice(0, 200)}${response.content.length > 200 ? '...' : ''}`); // Check if an image was generated (indicating tool was used) try { const files = await fs.readdir(TEST_OUTPUT_DIR); const imageFiles = files.filter(file => file.endsWith('.png') || file.endsWith('.jpg') || file.endsWith('.jpeg')); if (imageFiles.length > 0) { console.log('๐ŸŽจ Image generation tool was used!'); console.log(`๐Ÿ“ Generated file: ${imageFiles[imageFiles.length - 1]}`); // The fact that an image was generated means the agent used the tool // and hopefully followed our guidance for creative prompts console.log('โœ… Agent successfully used image generation tool'); console.log('๐Ÿ’ก The enhanced tool instructions should have guided the agent'); console.log(' to create a more detailed and creative prompt'); } else { console.log('โŒ No image files found - tool may not have been used'); } } catch (error) { console.log('โŒ Could not check for generated files'); } } catch (error) { console.log('โŒ Test case failed:', error.message); } } } async cleanup() { console.log('\n๐Ÿงน Test completed!'); console.log(''); console.log('๐Ÿ“‹ Summary:'); console.log(' - The agent should now create more detailed, creative prompts'); console.log(' - Simple user requests should be transformed into rich descriptions'); console.log(' - Generated images should have better quality due to enhanced prompts'); console.log(''); } async runTest() { try { await this.setup(); await this.testSimpleToCreativePrompt(); await this.cleanup(); console.log('๐ŸŽ‰ Creative prompt generation test completed!'); } catch (error) { console.error('โŒ Test failed:', error); process.exit(1); } } } // Run the test async function runCreativePromptTest() { console.log('๐Ÿš€ Starting Creative Prompt Generation Test'); console.log(''); console.log('This test verifies that:'); console.log(' - Agent receives enhanced tool instructions'); console.log(' - Agent transforms simple requests into creative prompts'); console.log(' - Generated prompts include artistic and technical details'); console.log(''); const test = new CreativePromptTest(); await test.runTest(); } // Run if called directly if (import.meta.url === `file://${process.argv[1]}`) { runCreativePromptTest(); }