-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
31 lines (26 loc) · 810 Bytes
/
utils.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
import { Configuration, OpenAIApi } from "openai";
import chalk from "chalk";
export const processFlags = (flags) => {
process.argv
.filter((arg) => {
return (
arg.startsWith("-") &&
Object.keys(flags).includes(arg.replace(/^-+/, ""))
);
})
.map((arg) => arg.replace(/^-+/, ""))
.forEach((flag) => {
flags[flag] = true;
});
return flags;
};
export const log = {
debug: (title, msg) =>
console.log(chalk.yellow(`\n[DEBUG] - ${title}\n`), msg),
error: (title, msg) => console.log(chalk.red(`\n[ERROR] - ${title}\n`), msg),
info: (title, msg) => console.log(chalk.cyan(`\n[INFO] - ${title}`), msg),
};
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_TOKEN,
});
export const openai = new OpenAIApi(configuration);