-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-client.mjs
More file actions
58 lines (48 loc) · 1.48 KB
/
test-client.mjs
File metadata and controls
58 lines (48 loc) · 1.48 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
// Простой тестовый клиент для проверки прокси
const API_KEY = process.env.AGENT_ROUTER_TOKEN || "sk-test";
const MODEL = process.env.OPENAI_MODEL || "gpt-5";
console.log("========================================");
console.log("Тест Node.js клиента -> прокси");
console.log("========================================");
console.log(`API_KEY: ${API_KEY.substring(0, 20)}...`);
console.log(`MODEL: ${MODEL}`);
console.log("");
const requestBody = {
model: MODEL,
messages: [{ role: "user", content: "Say hello" }],
max_tokens: 50,
};
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
},
body: JSON.stringify(requestBody),
};
console.log(
"Отправка запроса к http://localhost:8787/agentrouter/v1/chat/completions"
);
console.log("");
try {
const response = await fetch(
"http://localhost:8787/agentrouter/v1/chat/completions",
options
);
console.log(`Статус: ${response.status} ${response.statusText}`);
console.log("");
const data = await response.text();
console.log("Ответ:");
console.log(data);
if (response.ok) {
console.log("");
console.log("✅ Успех!");
} else {
console.log("");
console.log("❌ Ошибка!");
}
} catch (err) {
console.error("❌ Ошибка запроса:", err.message);
}
console.log("");
console.log("========================================");