feat: basic usage stats
This commit is contained in:
parent
91792bf8bf
commit
55b110a220
1 changed files with 15 additions and 3 deletions
18
index.ts
18
index.ts
|
|
@ -27,17 +27,21 @@ try {
|
||||||
const prompt = Bun.argv[2] ?? "Introduce yourself.";
|
const prompt = Bun.argv[2] ?? "Introduce yourself.";
|
||||||
messages.push({ role: "user", content: prompt });
|
messages.push({ role: "user", content: prompt });
|
||||||
|
|
||||||
const { fullStream, reasoningText, text } = streamText({
|
const { fullStream, reasoningText, text, totalUsage } = streamText({
|
||||||
model: provider("qwen3.5-35b-a3b"),
|
model: provider("qwen3.5-35b-a3b"),
|
||||||
messages,
|
messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
|
||||||
renderStream(fullStream);
|
renderStream(fullStream);
|
||||||
|
|
||||||
const reasoning = await reasoningText;
|
const reasoning = await reasoningText;
|
||||||
await reasoningFile.write(reasoning ?? "");
|
|
||||||
|
|
||||||
const response = await text;
|
const response = await text;
|
||||||
|
|
||||||
|
const stop = Date.now();
|
||||||
|
|
||||||
|
await reasoningFile.write(reasoning ?? "");
|
||||||
await responseFile.write(response);
|
await responseFile.write(response);
|
||||||
|
|
||||||
messages.push({ role: "assistant", content: response });
|
messages.push({ role: "assistant", content: response });
|
||||||
|
|
@ -48,3 +52,11 @@ Bun.spawnSync({
|
||||||
cmd: ["glow", "-w", `${numColumns}`, responsePath],
|
cmd: ["glow", "-w", `${numColumns}`, responsePath],
|
||||||
stdio: ["inherit", "inherit", "inherit"],
|
stdio: ["inherit", "inherit", "inherit"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { inputTokens, outputTokens } = await totalUsage;
|
||||||
|
const context = (inputTokens ?? 0) / 1000;
|
||||||
|
const output = (outputTokens ?? 0) / 1000;
|
||||||
|
const time = (stop - start) / 1000;
|
||||||
|
process.stderr.write(
|
||||||
|
`Context: ${context.toFixed(1)}k, Output: ${output.toFixed(1)}k, Time: ${time.toFixed(2)}s\n`,
|
||||||
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue