-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.html
More file actions
247 lines (227 loc) Β· 9.1 KB
/
test_api.html
File metadata and controls
247 lines (227 loc) Β· 9.1 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FloatChat API Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
min-height: 100vh;
}
.container {
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}
.test-section {
margin: 20px 0;
padding: 20px;
background: rgba(255,255,255,0.1);
border-radius: 10px;
border-left: 4px solid #4CAF50;
}
button {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
margin: 5px;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
}
button:disabled {
background: #666;
cursor: not-allowed;
transform: none;
}
.result {
margin-top: 15px;
padding: 15px;
background: rgba(0,0,0,0.3);
border-radius: 8px;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
font-size: 14px;
}
.success { border-left: 4px solid #4CAF50; }
.error { border-left: 4px solid #f44336; }
.loading { opacity: 0.7; }
input, textarea {
width: 100%;
padding: 12px;
border: none;
border-radius: 8px;
background: rgba(255,255,255,0.9);
color: #333;
margin: 10px 0;
font-size: 16px;
}
h1, h2 { text-align: center; margin-bottom: 30px; }
.status { padding: 10px; border-radius: 8px; margin: 10px 0; }
.online { background: rgba(76, 175, 80, 0.3); }
.offline { background: rgba(244, 67, 54, 0.3); }
</style>
</head>
<body>
<div class="container">
<h1>π FloatChat API Test Dashboard</h1>
<div class="test-section">
<h2>π API Health Check</h2>
<button onclick="testHealth()">Test Health Endpoint</button>
<div id="healthResult" class="result"></div>
</div>
<div class="test-section">
<h2>π€ AI Chat Test</h2>
<textarea id="chatInput" placeholder="Enter your ocean data question..." rows="3">What is the temperature of the Arabian Sea?</textarea>
<button onclick="testChat()">Send Chat Query</button>
<div id="chatResult" class="result"></div>
</div>
<div class="test-section">
<h2>πΊοΈ ARGO Data Test</h2>
<button onclick="testArgoData()">Get ARGO Floats</button>
<div id="argoResult" class="result"></div>
</div>
<div class="test-section">
<h2>π€ Voice Service Test</h2>
<button onclick="testVoice()">Test Voice Synthesis</button>
<div id="voiceResult" class="result"></div>
</div>
<div class="test-section">
<h2>π System Status</h2>
<div id="systemStatus">
<div class="status offline">π΄ Backend: Checking...</div>
<div class="status offline">π΄ Database: Checking...</div>
<div class="status offline">π΄ AI Service: Checking...</div>
<div class="status offline">π΄ Voice Service: Checking...</div>
</div>
</div>
</div>
<script>
const API_BASE = 'http://localhost:8000';
async function makeRequest(url, options = {}) {
try {
const response = await fetch(API_BASE + url, {
headers: {
'Content-Type': 'application/json',
...options.headers
},
...options
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
throw error;
}
}
function updateResult(elementId, data, isError = false) {
const element = document.getElementById(elementId);
element.textContent = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
element.className = `result ${isError ? 'error' : 'success'}`;
}
function setLoading(elementId, isLoading) {
const element = document.getElementById(elementId);
if (isLoading) {
element.textContent = 'Loading...';
element.className = 'result loading';
}
}
async function testHealth() {
setLoading('healthResult', true);
try {
const data = await makeRequest('/health');
updateResult('healthResult', data);
updateSystemStatus(data);
} catch (error) {
updateResult('healthResult', `β Health check failed: ${error.message}`, true);
}
}
async function testChat() {
const query = document.getElementById('chatInput').value;
if (!query.trim()) {
updateResult('chatResult', 'β Please enter a question', true);
return;
}
setLoading('chatResult', true);
try {
const data = await makeRequest('/api/v1/chat/query', {
method: 'POST',
body: JSON.stringify({
message: query,
conversation_id: 'test-' + Date.now(),
language: 'en',
voice_input: false,
voice_output: false
})
});
updateResult('chatResult', data);
} catch (error) {
updateResult('chatResult', `β Chat test failed: ${error.message}`, true);
}
}
async function testArgoData() {
setLoading('argoResult', true);
try {
const data = await makeRequest('/api/v1/floats?limit=5');
updateResult('argoResult', data);
} catch (error) {
updateResult('argoResult', `β ARGO data test failed: ${error.message}`, true);
}
}
async function testVoice() {
setLoading('voiceResult', true);
try {
const data = await makeRequest('/api/v1/voice/synthesize', {
method: 'POST',
body: JSON.stringify({
text: 'Hello from FloatChat! Ocean data analysis is working.',
language: 'en'
})
});
updateResult('voiceResult', data);
} catch (error) {
updateResult('voiceResult', `β Voice test failed: ${error.message}`, true);
}
}
function updateSystemStatus(healthData) {
const statusDiv = document.getElementById('systemStatus');
const dependencies = healthData.dependencies || {};
const features = healthData.features || {};
statusDiv.innerHTML = `
<div class="status ${healthData.status === 'healthy' ? 'online' : 'offline'}">
${healthData.status === 'healthy' ? 'π’' : 'π΄'} Backend: ${healthData.status}
</div>
<div class="status ${dependencies.gemini_ai ? 'online' : 'offline'}">
${dependencies.gemini_ai ? 'π’' : 'π΄'} AI Service: ${dependencies.gemini_ai ? 'Online' : 'Offline'}
</div>
<div class="status ${features.voice_processing ? 'online' : 'offline'}">
${features.voice_processing ? 'π’' : 'π΄'} Voice Service: ${features.voice_processing ? 'Available' : 'Limited'}
</div>
<div class="status ${features.real_argo_data ? 'online' : 'offline'}">
${features.real_argo_data ? 'π’' : 'π΄'} ARGO Data: ${features.real_argo_data ? 'Available' : 'Offline'}
</div>
`;
}
// Auto-test health on page load
window.addEventListener('load', () => {
setTimeout(testHealth, 1000);
});
// Auto-refresh health every 30 seconds
setInterval(testHealth, 30000);
</script>
</body>
</html>