UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

155 lines (154 loc) โ€ข 7.3 kB
import { ChatService } from '../services/chatService.js'; import { PROVIDER_CAPABILITIES } from '../services/llm/types.js'; async function testEndToEndConversation() { console.log('๐Ÿงช End-to-End Conversation Architecture Test'); console.log('='.repeat(60)); const chatService = new ChatService(); // Test 1: Conversation Provider Flow (Mock) console.log('\n๐Ÿ“‹ Test 1: Conversation Provider Flow (OpenAI Mock)'); console.log('-'.repeat(50)); try { // Create session const session = await chatService.createSession({ systemPrompt: 'You are a helpful AI assistant for testing.' }); console.log(`โœ… Session created: ${session.id}`); // Mock the LLM provider to avoid actual API calls const originalGetLLMProvider = chatService['getLLMProvider']; chatService['getLLMProvider'] = async () => ({ supportsConversation: () => true, getCapabilities: () => PROVIDER_CAPABILITIES.OpenAI, executeConversation: async (messages) => { console.log(`๐Ÿค– Mock OpenAI received ${messages.length} messages:`); messages.forEach((msg, i) => { console.log(` ${i + 1}. ${msg.role}: ${msg.content.substring(0, 50)}...`); }); return { content: 'This is a mock response from OpenAI using conversation format.', raw: { mock: true } }; }, executePrompt: async () => ({ content: 'Should not be called', raw: {} }), executePrompts: async () => [{ content: 'Should not be called', raw: {} }], configure: () => { }, getConfig: () => ({}), isConfigured: async () => true }); // Send a message const response = await chatService.sendMessage(session.id, 'Hello, can you help me test the conversation architecture?', { provider: 'OpenAI' }); console.log(`โœ… Response received: ${response.content.substring(0, 100)}...`); console.log(`โœ… Response role: ${response.role}`); // Restore original method chatService['getLLMProvider'] = originalGetLLMProvider; } catch (error) { console.log(`โŒ Error in conversation provider test: ${error}`); } // Test 2: Simple Prompt Provider Flow (Mock) console.log('\n๐Ÿ“‹ Test 2: Simple Prompt Provider Flow (Ollama Mock)'); console.log('-'.repeat(50)); try { // Create session const session = await chatService.createSession({ systemPrompt: 'You are a helpful AI assistant for testing.' }); console.log(`โœ… Session created: ${session.id}`); // Mock the LLM provider for simple prompt const originalGetLLMProvider = chatService['getLLMProvider']; chatService['getLLMProvider'] = async () => ({ supportsConversation: () => false, getCapabilities: () => PROVIDER_CAPABILITIES.Ollama, executePrompt: async (prompt) => { console.log(`๐Ÿค– Mock Ollama received prompt (${prompt.length} chars):`); console.log(` Preview: ${prompt.substring(0, 100)}...`); console.log(` Contains System: ${prompt.includes('System:')}`); console.log(` Contains Human: ${prompt.includes('Human:')}`); return { content: 'This is a mock response from Ollama using prompt format.', raw: { mock: true } }; }, executeConversation: async () => ({ content: 'Should not be called', raw: {} }), executePrompts: async () => [{ content: 'Should not be called', raw: {} }], configure: () => { }, getConfig: () => ({}), isConfigured: async () => true }); // Send a message const response = await chatService.sendMessage(session.id, 'Hello, can you help me test the simple prompt architecture?', { provider: 'Ollama' }); console.log(`โœ… Response received: ${response.content.substring(0, 100)}...`); console.log(`โœ… Response role: ${response.role}`); // Restore original method chatService['getLLMProvider'] = originalGetLLMProvider; } catch (error) { console.log(`โŒ Error in simple prompt provider test: ${error}`); } // Test 3: Provider Capability Detection console.log('\n๐Ÿ“‹ Test 3: Provider Capability Detection'); console.log('-'.repeat(50)); const testProviders = ['OpenAI', 'Anthropic', 'DeepSeek', 'OpenRouter', 'HuggingFace', 'Ollama', 'Gemini']; for (const provider of testProviders) { const capabilities = PROVIDER_CAPABILITIES[provider]; if (capabilities) { const type = capabilities.supportsConversation ? 'Conversation' : 'Simple Prompt'; const format = capabilities.customFormat || 'standard'; console.log(`โœ… ${provider}: ${type} (${format})`); } else { console.log(`โŒ ${provider}: No capabilities defined`); } } // Test 4: Message Filtering for UI console.log('\n๐Ÿ“‹ Test 4: Message Filtering for UI'); console.log('-'.repeat(50)); try { const session = await chatService.createSession({ systemPrompt: 'Test system prompt' }); // Add some messages including tool responses session.messages.push({ id: 'user1', role: 'user', content: 'User message 1', timestamp: Date.now() }); session.messages.push({ id: 'assistant1', role: 'assistant', content: 'Assistant response 1', timestamp: Date.now() }); session.messages.push({ id: 'tool1', role: 'user', content: '<tool_response>...</tool_response>', timestamp: Date.now(), metadata: { internal: true, isToolResponse: true } }); session.messages.push({ id: 'user2', role: 'user', content: 'User message 2', timestamp: Date.now() }); const allMessages = session.messages; const uiMessages = chatService.getMessages(session.id); console.log(`โœ… Total messages in session: ${allMessages.length}`); console.log(`โœ… Messages visible to UI: ${uiMessages.length}`); console.log(`โœ… Internal messages filtered: ${allMessages.length - uiMessages.length === 1}`); } catch (error) { console.log(`โŒ Error in message filtering test: ${error}`); } console.log('\n๐ŸŽ‰ End-to-End Conversation Architecture Test Complete!'); console.log('\n๐Ÿ“Š Summary:'); console.log('- โœ… Conversation providers use message arrays'); console.log('- โœ… Simple prompt providers use concatenated strings'); console.log('- โœ… Provider capabilities correctly detected'); console.log('- โœ… Message filtering works for UI display'); console.log('- โœ… Hybrid architecture successfully implemented'); console.log('\n๐Ÿš€ Ready for production testing with real API keys!'); } // Run the test testEndToEndConversation().catch(console.error);