-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (42 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import dotenv from "dotenv-flow";
import inquirer from "inquirer";
import process from "node:process";
import { fileURLToPath } from "node:url";
import { parseArgs } from "node:util";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
process.chdir(__dirname);
dotenv.config({
node_env: process.env.APP_ENV || process.env.NODE_ENV || "development",
silent: true,
});
// https://2ality.com/2022/08/node-util-parseargs.html
const {
values: { model },
} = parseArgs({
options: {
model: {
type: "string",
},
},
});
if (typeof model === "undefined") {
throw new TypeError(
"[ERR_PARSE_ARGS_INVALID_OPTION_VALUE]: Option '--model <value>' argument missing"
);
}
const questions = [
{
type: "input",
name: "prompt",
message: "prompt",
validate(text) {
if (text.length === 0) {
return "[ERR_PARSE_ARGS_INVALID_OPTION_VALUE]: Option '--prompt <value>' argument missing";
}
return true;
},
},
];
const { prompt } = await inquirer.prompt(questions);
const { createCompletion } = await import("./createCompletion.js");
createCompletion({ model, prompt });