-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_advanced.js
More file actions
50 lines (43 loc) · 1.87 KB
/
test_advanced.js
File metadata and controls
50 lines (43 loc) · 1.87 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
async function testModel(modelName, prompt) {
console.log(`\n\x1b[36m--- Testing ${modelName} with STREAMING ---\x1b[0m`);
const res = await fetch('http://localhost:3000/v1/chat/completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: modelName,
stream: true,
messages: [{ role: "user", content: prompt }]
})
});
// Process the active event stream text chunks
const reader = res.body.getReader();
const decoder = new TextDecoder("utf-8");
// Quick aesthetic parser for terminal output
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunkStr = decoder.decode(value);
const lines = chunkStr.split('\n');
for (const line of lines) {
if (line.startsWith('data: ') && line !== 'data: [DONE]') {
const dataStr = line.substring(6);
try {
const data = JSON.parse(dataStr);
if (data.choices[0].delta.content) {
process.stdout.write("\x1b[33m" + data.choices[0].delta.content + "\x1b[0m");
}
} catch(e) {}
}
}
}
console.log("\n\x1b[32m--- Stream Complete ---\x1b[0m");
}
async function runAll() {
console.log("WAITING 3 SECONDS FOR SERVER TO BOOT...");
await new Promise(r => setTimeout(r, 3000));
// Test ChatGPT with a MASSIVE prompt to test streaming stability!
await testModel("chatgpt-web", "Write a detailed, 5-paragraph essay on the history of the printing press. Include specific dates and figures.");
// This will instruct Playwright to navigate to claude.ai dynamically!
// await testModel("claude-web", "Write a 3 word poem about the earth.");
}
runAll();