feat: format thinking better
This commit is contained in:
parent
9d970bca49
commit
b0e7eb2a3d
1 changed files with 10 additions and 4 deletions
14
index.ts
14
index.ts
|
|
@ -8,18 +8,18 @@ const provider = createOpenAICompatible({
|
||||||
includeUsage: true, // Include usage information in streaming responses
|
includeUsage: true, // Include usage information in streaming responses
|
||||||
});
|
});
|
||||||
|
|
||||||
const { fullStream } = streamText({
|
const { fullStream, reasoningText, text } = streamText({
|
||||||
model: provider("qwen3.5-35b-a3b"),
|
model: provider("qwen3.5-35b-a3b"),
|
||||||
prompt: Bun.argv[2]!,
|
prompt: Bun.argv[2]!,
|
||||||
});
|
});
|
||||||
|
|
||||||
for await (const part of fullStream) {
|
for await (const part of fullStream) {
|
||||||
if (part.type === "reasoning-start") {
|
if (part.type === "reasoning-start") {
|
||||||
process.stdout.write("<think>\n");
|
process.stdout.write("\u001b[2m\n ");
|
||||||
} else if (part.type === "reasoning-delta") {
|
} else if (part.type === "reasoning-delta") {
|
||||||
process.stdout.write(part.text);
|
process.stdout.write(part.text.replaceAll('\n', '\n '));
|
||||||
} else if (part.type === "reasoning-end") {
|
} else if (part.type === "reasoning-end") {
|
||||||
process.stdout.write("\n</think>");
|
process.stdout.write("\n\u001b[22m");
|
||||||
} else if (part.type === "text-start") {
|
} else if (part.type === "text-start") {
|
||||||
process.stdout.write("\n");
|
process.stdout.write("\n");
|
||||||
} else if (part.type === "text-delta") {
|
} else if (part.type === "text-delta") {
|
||||||
|
|
@ -28,3 +28,9 @@ for await (const part of fullStream) {
|
||||||
process.stdout.write("\n");
|
process.stdout.write("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reasoning = await reasoningText;
|
||||||
|
const response = await text;
|
||||||
|
|
||||||
|
Bun.file("reasoning.md").write(reasoning ?? "");
|
||||||
|
Bun.file("response.md").write(response);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue