Spaces:
Running
Running
File size: 9,289 Bytes
60a5726 92aa273 60a5726 92aa273 60a5726 92aa273 60a5726 92aa273 60a5726 |
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
import React, { useState, useEffect } from 'react';
import './App.css';
function App() {
const [isConnected, setIsConnected] = useState(false);
const [messages, setMessages] = useState([]);
const [inputMessage, setInputMessage] = useState('');
const [agentType, setAgentType] = useState('intent');
const [loading, setLoading] = useState(false);
const [serverUrl, setServerUrl] = useState('http://localhost:8080');
// Test different agent endpoints
const agentEndpoints = {
intent: '/api/intent',
order: '/api/order',
support: '/api/support'
};
const testServerConnection = async () => {
try {
const response = await fetch(`${serverUrl}/health`);
if (response.ok) {
setIsConnected(true);
addMessage('System', 'Connected to AI Agent server');
} else {
setIsConnected(false);
addMessage('System', 'Server not responding');
}
} catch (error) {
setIsConnected(false);
addMessage('System', `Connection failed: ${error.message}`);
}
};
const addMessage = (sender, content) => {
setMessages(prev => [...prev, {
id: Date.now(),
sender,
content,
timestamp: new Date().toLocaleTimeString()
}]);
};
const testAgent = async () => {
if (!inputMessage.trim()) return;
setLoading(true);
addMessage('User', inputMessage);
try {
let requestBody;
// Prepare request based on agent type
switch (agentType) {
case 'intent':
requestBody = { query: inputMessage };
break;
case 'order':
requestBody = {
customerId: 'test-customer-123',
productId: 'test-product-456',
quantity: 1,
paymentMethod: 'card'
};
break;
case 'support':
requestBody = {
customerId: 'test-customer-123',
query: inputMessage,
channel: 'chat'
};
break;
default:
requestBody = { query: inputMessage };
}
const response = await fetch(`${serverUrl}${agentEndpoints[agentType]}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
const data = await response.json();
if (response.ok) {
addMessage(`${agentType} Agent`, JSON.stringify(data, null, 2));
} else {
addMessage('Error', `Request failed: ${data.error || 'Unknown error'}`);
}
} catch (error) {
addMessage('Error', `Network error: ${error.message}`);
} finally {
setLoading(false);
setInputMessage('');
}
};
const clearMessages = () => {
setMessages([]);
};
useEffect(() => {
testServerConnection();
}, [serverUrl]);
return (
<div className="App" style={{ padding: '20px', fontFamily: 'Arial, sans-serif' }}>
<header style={{ marginBottom: '20px' }}>
<h1>AI Agent System Tester</h1>
<div style={{ marginBottom: '10px' }}>
<label>Server URL: </label>
<input
type="text"
value={serverUrl}
onChange={(e) => setServerUrl(e.target.value)}
style={{ marginLeft: '10px', padding: '5px', width: '300px' }}
/>
<button onClick={testServerConnection} style={{ marginLeft: '10px' }}>
Test Connection
</button>
</div>
<div style={{
padding: '10px',
backgroundColor: isConnected ? '#d4edda' : '#f8d7da',
color: isConnected ? '#155724' : '#721c24',
borderRadius: '5px'
}}>
Status: {isConnected ? 'Connected' : 'Disconnected'}
</div>
</header>
<div style={{ display: 'flex', gap: '20px' }}>
{/* Control Panel */}
<div style={{ width: '300px' }}>
<h3>Test Configuration</h3>
<div style={{ marginBottom: '15px' }}>
<label>Agent Type:</label>
<select
value={agentType}
onChange={(e) => setAgentType(e.target.value)}
style={{ width: '100%', padding: '5px', marginTop: '5px' }}
>
<option value="intent">Intent Agent</option>
<option value="order">Order Processing Agent</option>
<option value="support">Customer Support Agent</option>
</select>
</div>
<div style={{ marginBottom: '15px' }}>
<label>Test Input:</label>
<textarea
value={inputMessage}
onChange={(e) => setInputMessage(e.target.value)}
placeholder={
agentType === 'intent' ? 'Enter a query to classify intent...' :
agentType === 'order' ? 'Order will use test data, but enter description...' :
'Enter customer support query...'
}
style={{
width: '100%',
height: '100px',
padding: '10px',
marginTop: '5px',
resize: 'vertical'
}}
/>
</div>
<div style={{ marginBottom: '15px' }}>
<button
onClick={testAgent}
disabled={loading || !isConnected}
style={{
width: '100%',
padding: '10px',
backgroundColor: loading || !isConnected ? '#ccc' : '#007bff',
color: 'white',
border: 'none',
borderRadius: '5px',
cursor: loading || !isConnected ? 'not-allowed' : 'pointer'
}}
>
{loading ? 'Testing...' : `Test ${agentType} Agent`}
</button>
</div>
<button
onClick={clearMessages}
style={{
width: '100%',
padding: '8px',
backgroundColor: '#6c757d',
color: 'white',
border: 'none',
borderRadius: '5px',
cursor: 'pointer'
}}
>
Clear Messages
</button>
{/* Quick Test Examples */}
<div style={{ marginTop: '20px' }}>
<h4>Quick Tests:</h4>
<div style={{ fontSize: '12px' }}>
<div>
<strong>Intent:</strong> "I want to place an order"
</div>
<div style={{ marginTop: '5px' }}>
<strong>Support:</strong> "My order is delayed"
</div>
<div style={{ marginTop: '5px' }}>
<strong>Order:</strong> Uses test customer data
</div>
</div>
</div>
</div>
{/* Messages Panel */}
<div style={{ flex: 1 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<h3>Test Results</h3>
<span style={{ fontSize: '12px', color: '#666' }}>
{messages.length} messages
</span>
</div>
<div style={{
height: '500px',
overflowY: 'auto',
border: '1px solid #ddd',
borderRadius: '5px',
padding: '10px',
backgroundColor: '#f8f9fa'
}}>
{messages.length === 0 ? (
<p style={{ color: '#666', textAlign: 'center', marginTop: '50px' }}>
No messages yet. Test an agent to see results.
</p>
) : (
messages.map(message => (
<div
key={message.id}
style={{
marginBottom: '15px',
padding: '10px',
backgroundColor: message.sender === 'User' ? '#e3f2fd' :
message.sender === 'System' ? '#fff3e0' :
message.sender === 'Error' ? '#ffebee' : '#f1f8e9',
borderRadius: '8px',
borderLeft: `4px solid ${
message.sender === 'User' ? '#2196f3' :
message.sender === 'System' ? '#ff9800' :
message.sender === 'Error' ? '#f44336' : '#4caf50'
}`
}}
>
<div style={{
display: 'flex',
justifyContent: 'space-between',
marginBottom: '5px'
}}>
<strong>{message.sender}</strong>
<span style={{ fontSize: '12px', color: '#666' }}>
{message.timestamp}
</span>
</div>
<div style={{
whiteSpace: 'pre-wrap',
fontFamily: message.content.startsWith('{') ? 'monospace' : 'inherit',
fontSize: message.content.startsWith('{') ? '12px' : '14px'
}}>
{message.content}
</div>
</div>
))
)}
</div>
</div>
</div>
</div>
);
}
export default App; |