feat: add args parsing; refactor scripts
This commit is contained in:
parent
b3cef4dd03
commit
bcd9771cd5
3 changed files with 59 additions and 41 deletions
26
index.ts
26
index.ts
|
|
@ -1,12 +1,27 @@
|
|||
import os from "node:os";
|
||||
import { parseArgs } from "node:util";
|
||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||
import { type ModelMessage, streamText } from "ai";
|
||||
|
||||
import { renderStream } from "./src/render";
|
||||
|
||||
const home = os.homedir();
|
||||
const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
||||
|
||||
const { values: args, positionals } = parseArgs({
|
||||
args: Bun.argv,
|
||||
options: {
|
||||
model: {
|
||||
type: "string",
|
||||
},
|
||||
new: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const provider = createOpenAICompatible({
|
||||
name: "llama.cpp",
|
||||
apiKey: "local",
|
||||
|
|
@ -16,16 +31,18 @@ const provider = createOpenAICompatible({
|
|||
|
||||
const messages: ModelMessage[] = [];
|
||||
|
||||
if (!args.new) {
|
||||
try {
|
||||
const convo = await convoFile.json();
|
||||
messages.push(...convo);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const prompt = Bun.argv[2] ?? "Introduce yourself.";
|
||||
const prompt = positionals[2] ?? "Introduce yourself.";
|
||||
messages.push({ role: "user", content: prompt });
|
||||
|
||||
const { fullStream, textStream, text, totalUsage } = streamText({
|
||||
model: provider("gemma4-26b-a4b"),
|
||||
model: provider(args.model ?? "gemma4-26b-a4b"),
|
||||
messages,
|
||||
});
|
||||
|
||||
|
|
@ -56,3 +73,6 @@ const time = (stop - start) / 1000;
|
|||
process.stderr.write(
|
||||
`\u001b[2mContext: ${context.toFixed(1)}k, Output: ${output.toFixed(1)}k, Time: ${time.toFixed(2)}s\u001b[22m\n`,
|
||||
);
|
||||
}
|
||||
|
||||
await main();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"dev": "bun run index.ts",
|
||||
"prod": "bun run out/index.js",
|
||||
"check": "bunx --bun @biomejs/biome check --write",
|
||||
"build": "bun run check && bun run build:bundle && bun run shebang",
|
||||
"build:js": "bun run check && bun run build:bundle && bun run shebang",
|
||||
"build:bundle": "bun build --target=bun --production --sourcemap --outdir=out index.ts",
|
||||
"build:bin": "bun build --compile --outfile=out/aicl index.ts",
|
||||
"shebang": "sed -i '1i#!\\/usr\\/bin\\/env bun' out/index.js"
|
||||
|
|
|
|||
|
|
@ -59,9 +59,7 @@ export async function renderStream(
|
|||
resetCounts();
|
||||
}
|
||||
|
||||
while (!memOk) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
}
|
||||
while (!memOk) await Bun.sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue