feat: add config file and short CLI aliases
This commit is contained in:
parent
ce12c51435
commit
95bec63a59
1 changed files with 24 additions and 8 deletions
32
index.ts
32
index.ts
|
|
@ -8,12 +8,10 @@ import StreamRenderer from "./src/render";
|
|||
const { values: args, positionals } = parseArgs({
|
||||
args: Bun.argv,
|
||||
options: {
|
||||
model: {
|
||||
type: "string",
|
||||
},
|
||||
new: {
|
||||
type: "boolean",
|
||||
},
|
||||
model: { type: "string" },
|
||||
m: { type: "string" },
|
||||
new: { type: "boolean" },
|
||||
n: { type: "boolean" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
|
|
@ -21,8 +19,26 @@ const { values: args, positionals } = parseArgs({
|
|||
|
||||
const home = os.homedir();
|
||||
const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
||||
const configFile = Bun.file(`${home}/.aicl_config.json`);
|
||||
|
||||
async function main() {
|
||||
let config: { model?: string };
|
||||
try {
|
||||
config = await configFile.json();
|
||||
} catch {
|
||||
config = {};
|
||||
}
|
||||
|
||||
config.model = args.model ?? args.m ?? config.model;
|
||||
const newConvo = args.new ?? args.n;
|
||||
|
||||
if (!config.model) {
|
||||
console.error("Please specify a model with --model/-m at least one time.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await configFile.write(JSON.stringify(config, null, " "));
|
||||
|
||||
const provider = createOpenAICompatible({
|
||||
name: "llama.cpp",
|
||||
apiKey: "local",
|
||||
|
|
@ -32,7 +48,7 @@ async function main() {
|
|||
|
||||
const messages: ModelMessage[] = [];
|
||||
|
||||
if (!args.new) {
|
||||
if (!newConvo) {
|
||||
try {
|
||||
const convo = await convoFile.json();
|
||||
messages.push(...convo);
|
||||
|
|
@ -43,7 +59,7 @@ async function main() {
|
|||
messages.push({ role: "user", content: prompt });
|
||||
|
||||
const { fullStream, textStream, text, totalUsage } = streamText({
|
||||
model: provider(args.model ?? "qwen3.5-35b-a3b"),
|
||||
model: provider(config.model),
|
||||
messages,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue