UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

46 lines (45 loc) • 2.94 kB
import { ChatService } from '../services/chatService.js'; async function demonstrateChatWithTools() { console.log('šŸ¤– Demonstrating Chat Service with Tool Architecture...\n'); try { // Initialize chat service with current directory const chatService = new ChatService(process.cwd()); // Create a chat session const session = chatService.createSession({ systemPrompt: `You are a helpful AI assistant with access to file reading tools. When users ask about files, use the read_file tool to access their contents. Always be helpful and provide detailed information about what you find.` }); console.log(`šŸ’¬ Created chat session: ${session.id}\n`); // Test 1: Ask about the project structure console.log('šŸ“‹ Test 1: Asking about project structure...'); const response1 = await chatService.sendMessage(session.id, "What files are available in this project? Can you give me an overview of the project structure?"); console.log('šŸ¤– Assistant:', response1.content.substring(0, 500) + '...\n'); // Test 2: Ask to read a specific file console.log('šŸ“– Test 2: Asking to read the README.md file...'); const response2 = await chatService.sendMessage(session.id, "Can you read the README.md file and tell me what this project is about? Use the read_file tool to access its contents."); console.log('šŸ¤– Assistant:', response2.content.substring(0, 800) + '...\n'); // Test 3: Ask about a specific file in the project console.log('šŸ“ Test 3: Asking about package.json...'); const response3 = await chatService.sendMessage(session.id, "What are the main dependencies of this project? Please read the package.json file to find out."); console.log('šŸ¤– Assistant:', response3.content.substring(0, 600) + '...\n'); console.log('āœ… Chat with tools demonstration completed successfully!'); console.log('\nšŸŽÆ Key Features Demonstrated:'); console.log('- āœ… File tree context in system prompt'); console.log('- āœ… Tool instructions provided to AI'); console.log('- āœ… Tool call parsing and execution'); console.log('- āœ… File reading with multiple formats'); console.log('- āœ… Conversational context maintained'); } catch (error) { console.error('āŒ Demo failed:', error); // Check if it's a configuration issue if (error instanceof Error && error.message.includes('not configured')) { console.log('\nšŸ’” Note: This demo requires an LLM provider to be configured.'); console.log(' Configure a provider first using the CLI configuration commands.'); } } } // Run the demo if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { demonstrateChatWithTools().catch(console.error); } export { demonstrateChatWithTools };