-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
31 lines (28 loc) · 915 Bytes
/
example.js
File metadata and controls
31 lines (28 loc) · 915 Bytes
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
// Test streaming through the proxy
const resp = await fetch("http://localhost:4097/v1/chat/completions", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "deepseek-v4-flash-free",
messages: [{ role: "user", content: "say hi in one word" }],
stream: true,
}),
});
console.log("Status:", resp.status);
console.log("Headers:", JSON.stringify([...resp.headers]));
let count = 0;
const reader = resp.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
count++;
const text = decoder.decode(value, { stream: true });
const lines = text.split("\n").filter(l => l.trim());
for (const line of lines) {
if (line.startsWith("data: ") && line !== "data: [DONE]") {
process.stdout.write(".");
}
}
}
console.log("\nTotal raw chunks received:", count);