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({
|
const { values: args, positionals } = parseArgs({
|
||||||
args: Bun.argv,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
model: {
|
model: { type: "string" },
|
||||||
type: "string",
|
m: { type: "string" },
|
||||||
},
|
new: { type: "boolean" },
|
||||||
new: {
|
n: { type: "boolean" },
|
||||||
type: "boolean",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
|
|
@ -21,8 +19,26 @@ const { values: args, positionals } = parseArgs({
|
||||||
|
|
||||||
const home = os.homedir();
|
const home = os.homedir();
|
||||||
const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
const convoFile = Bun.file(`${home}/.aicl_convo.json`);
|
||||||
|
const configFile = Bun.file(`${home}/.aicl_config.json`);
|
||||||
|
|
||||||
async function main() {
|
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({
|
const provider = createOpenAICompatible({
|
||||||
name: "llama.cpp",
|
name: "llama.cpp",
|
||||||
apiKey: "local",
|
apiKey: "local",
|
||||||
|
|
@ -32,7 +48,7 @@ async function main() {
|
||||||
|
|
||||||
const messages: ModelMessage[] = [];
|
const messages: ModelMessage[] = [];
|
||||||
|
|
||||||
if (!args.new) {
|
if (!newConvo) {
|
||||||
try {
|
try {
|
||||||
const convo = await convoFile.json();
|
const convo = await convoFile.json();
|
||||||
messages.push(...convo);
|
messages.push(...convo);
|
||||||
|
|
@ -43,7 +59,7 @@ async function main() {
|
||||||
messages.push({ role: "user", content: prompt });
|
messages.push({ role: "user", content: prompt });
|
||||||
|
|
||||||
const { fullStream, textStream, text, totalUsage } = streamText({
|
const { fullStream, textStream, text, totalUsage } = streamText({
|
||||||
model: provider(args.model ?? "qwen3.5-35b-a3b"),
|
model: provider(config.model),
|
||||||
messages,
|
messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue