-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-test.html
More file actions
65 lines (56 loc) · 2.51 KB
/
simple-test.html
File metadata and controls
65 lines (56 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<title>Simple API Test</title>
</head>
<body>
<div>
<input type="text" id="testInput" value="I need a router" />
<button onclick="testQuery()">Test</button>
<div id="result"></div>
</div>
<script>
async function testQuery() {
const message = document.getElementById('testInput').value;
const resultDiv = document.getElementById('result');
try {
console.log('Sending request:', message);
const response = await fetch('http://localhost:3001/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message })
});
console.log('Response status:', response.status);
console.log('Response ok:', response.ok);
const result = await response.json();
console.log('Full result:', result);
if (!result.success) {
resultDiv.innerHTML = `<p style="color: red;">Error: ${result.error}</p>`;
} else {
const data = result.data;
console.log('Data:', data);
console.log('Intent:', data.intent);
console.log('Result:', data.result);
let html = `<p><strong>Intent:</strong> ${data.intent}</p>`;
if (data.intent === 'product_recommendation' && Array.isArray(data.result)) {
html += '<h3>Recommendations:</h3>';
data.result.forEach(product => {
html += `<p>- ${product.name} (${product.category})</p>`;
});
} else if (data.result && data.result.error) {
html += `<p style="color: orange;">Result Error: ${data.result.error}</p>`;
} else {
html += `<p>Result: ${JSON.stringify(data.result)}</p>`;
}
resultDiv.innerHTML = html;
}
} catch (error) {
console.error('Error:', error);
resultDiv.innerHTML = `<p style="color: red;">Network Error: ${error.message}</p>`;
}
}
</script>
</body>
</html>