feat: send arg as prompt and stream to stdout
This commit is contained in:
parent
ae63c3bb0f
commit
9d970bca49
3 changed files with 60 additions and 1 deletions
31
index.ts
31
index.ts
|
|
@ -1 +1,30 @@
|
|||
console.log("Hello via Bun!");
|
||||
import { streamText } from "ai";
|
||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||
|
||||
const provider = createOpenAICompatible({
|
||||
name: "llama.cpp",
|
||||
apiKey: "local",
|
||||
baseURL: "http://127.0.0.1:8080/v1",
|
||||
includeUsage: true, // Include usage information in streaming responses
|
||||
});
|
||||
|
||||
const { fullStream } = 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("<think>\n");
|
||||
} else if (part.type === "reasoning-delta") {
|
||||
process.stdout.write(part.text);
|
||||
} else if (part.type === "reasoning-end") {
|
||||
process.stdout.write("\n</think>");
|
||||
} else if (part.type === "text-start") {
|
||||
process.stdout.write("\n");
|
||||
} else if (part.type === "text-delta") {
|
||||
process.stdout.write(part.text);
|
||||
} else if (part.type === "text-end") {
|
||||
process.stdout.write("\n");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue