model_chat/bin/ds-lib/main.js
2026-01-04 12:10:06 +08:00

49 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { chat, reason, setKey, setPrompt, viewPrompt } from './commands.js';
import { printInfo } from './output.js';
function usage(exit = true) {
printInfo(`用法:
ds k <key> 设置/替换 API 密钥
ds s <prompt> 设置系统提示词
ds v 查看当前提示词
ds c <text> 使用 deepseek-chat流式
ds r <text> 使用 deepseek-reasoner流式含思考
环境优先级: 命令行 > 环境变量 DEEPSEEK_API_KEY > 配置文件
默认模型: deepseek-reasoner`);
if (exit) process.exit(1);
}
export async function main(argv) {
if (!argv || argv.length === 0 || ['-h', '--help'].includes(argv[0])) {
usage(false);
return;
}
const [cmd, ...rest] = argv;
switch (cmd) {
case 'k':
await setKey(rest);
break;
case 's':
await setPrompt(rest);
break;
case 'v':
viewPrompt();
break;
case 'c':
await chat(rest);
break;
case 'r':
await reason(rest);
break;
default:
usage();
}
}
// 若作为独立模块直接调用
if (process.argv[1] === new URL(import.meta.url).pathname) {
main(process.argv.slice(2));
}