contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
46 lines (45 loc) ⢠2.94 kB
JavaScript
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 };