contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
58 lines (57 loc) โข 3.25 kB
JavaScript
import { Command } from 'commander';
import { ChatService } from '../services/chatService.js';
export function createTestCommandToolCommand() {
const command = new Command('test-command-tool');
command
.description('Test the command execution tool functionality')
.action(async () => {
console.log('๐งช Testing Command Execution Tool...\n');
try {
const chatService = new ChatService(process.cwd());
// Create a chat session
const session = await chatService.createSession({
systemPrompt: `You are a helpful AI assistant with access to command execution tools. When users ask you to run commands, use the execute_command tool to run them safely. Always provide clear information about the command results.`
});
console.log(`๐ฌ Created test session: ${session.id}\n`);
// Test 1: Ask AI to run pwd command
console.log('๐ Test 1: Asking AI to run pwd command...');
const response1 = await chatService.sendMessage(session.id, "Please use the execute_command tool to run 'pwd' and tell me what directory we're in.", {
provider: 'openai',
model: 'gpt-4o-mini',
temperature: 0.1
});
console.log('๐ค AI Response:', response1.content.substring(0, 200) + '...\n');
// Test 2: Ask AI to list files
console.log('๐ Test 2: Asking AI to list files in current directory...');
const response2 = await chatService.sendMessage(session.id, "Now use the execute_command tool to run 'ls -la' and show me the files in the current directory.", {
provider: 'openai',
model: 'gpt-4o-mini',
temperature: 0.1
});
console.log('๐ค AI Response:', response2.content.substring(0, 200) + '...\n');
// Test 3: Ask AI to check git status
console.log('๐ Test 3: Asking AI to check git status...');
const response3 = await chatService.sendMessage(session.id, "Please use the execute_command tool to run 'git status --porcelain' and tell me about any changes in the repository.", {
provider: 'openai',
model: 'gpt-4o-mini',
temperature: 0.1
});
console.log('๐ค AI Response:', response3.content.substring(0, 200) + '...\n');
// Test 4: Ask AI to check Node.js version
console.log('๐ Test 4: Asking AI to check Node.js version...');
const response4 = await chatService.sendMessage(session.id, "Use the execute_command tool to run 'node --version' and tell me what version of Node.js we're using.", {
provider: 'openai',
model: 'gpt-4o-mini',
temperature: 0.1
});
console.log('๐ค AI Response:', response4.content.substring(0, 200) + '...\n');
console.log('โ
Command execution tool testing completed successfully!');
}
catch (error) {
console.error('โ Error during testing:', error);
process.exit(1);
}
});
return command;
}