-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
48 lines (41 loc) · 1.26 KB
/
test-api.js
File metadata and controls
48 lines (41 loc) · 1.26 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
const axios = require('axios');
async function testApi() {
try {
console.log('测试API服务...');
// 测试健康检查
const healthResponse = await axios.get('http://localhost:3001/health');
console.log('健康检查:', healthResponse.data);
// 测试状态端点
const statusResponse = await axios.get('http://localhost:3001/v1/status', {
headers: {
'Authorization': 'Bearer sk-123'
}
});
console.log('状态检查:', JSON.stringify(statusResponse.data, null, 2));
// 测试聊天完成
const chatResponse = await axios.post('http://localhost:3001/v1/chat/completions', {
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: '你好'
}
]
}, {
headers: {
'Authorization': 'Bearer sk-123',
'Content-Type': 'application/json'
}
});
console.log('聊天测试成功:', chatResponse.data);
} catch (error) {
console.error('测试失败:');
if (error.response) {
console.error('状态码:', error.response.status);
console.error('错误数据:', JSON.stringify(error.response.data, null, 2));
} else {
console.error('错误信息:', error.message);
}
}
}
testApi();