diff --git a/index.ts b/index.ts index afed4d7..d37a59a 100644 --- a/index.ts +++ b/index.ts @@ -8,18 +8,18 @@ const provider = createOpenAICompatible({ includeUsage: true, // Include usage information in streaming responses }); -const { fullStream } = streamText({ +const { fullStream, reasoningText, text } = streamText({ model: provider("qwen3.5-35b-a3b"), prompt: Bun.argv[2]!, }); for await (const part of fullStream) { if (part.type === "reasoning-start") { - process.stdout.write("\n"); + process.stdout.write("\u001b[2m\n "); } 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") { - process.stdout.write("\n"); + process.stdout.write("\n\u001b[22m"); } else if (part.type === "text-start") { process.stdout.write("\n"); } else if (part.type === "text-delta") { @@ -28,3 +28,9 @@ for await (const part of fullStream) { process.stdout.write("\n"); } } + +const reasoning = await reasoningText; +const response = await text; + +Bun.file("reasoning.md").write(reasoning ?? ""); +Bun.file("response.md").write(response);