Files
musica-ia/test-node.js

46 lines
1.3 KiB
JavaScript

// Simple Node.js test to verify API connection
const fetch = require('node-fetch');
async function testChat() {
console.log('Testing chat API...');
console.log('Sending POST to http://localhost:8000/api/chat');
console.log('Request body:', JSON.stringify({
user_id: 'default-user',
message: 'hola',
}));
try {
const response = await fetch('http://localhost:8000/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
user_id: 'default-user',
message: 'hola',
}),
});
console.log('Response status:', response.status, response.statusText);
console.log('Response OK:', response.ok);
if (!response.ok) {
console.error('Error: Response not OK');
return;
}
const data = await response.json();
console.log('Response received successfully!');
console.log('AI Response:', data.response.substring(0, 150) + '...');
console.log('Success! The API is working correctly.');
process.exit(0);
} catch (error) {
console.error('ERROR:', error.message);
console.error('Stack:', error.stack);
process.exit(1);
}
}
testChat();