-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·49 lines (41 loc) · 1.38 KB
/
app.js
File metadata and controls
executable file
·49 lines (41 loc) · 1.38 KB
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
#!/usr/bin/env node
const { program } = require("commander");
const Config = require("./Config");
const { openAIApi, OpenAICommand, roles } = require("./OpenAICommand");
program
.option("-p, --prompt <prompt>", "Send a prompt to OpenAI API")
.option("--fate", "Tell me my fate today")
.option("--add-token <token>", "Add access token to configuration")
.option("--remove-token", "Remove access token from configuration")
.parse(process.argv);
const options = program.opts();
if (options.addToken) {
Config.update("ACCESS_TOKEN", options.addToken);
console.log("Access token added to configuration");
} else if (options.removeToken) {
Config.removeConfig();
console.log("Access token removed from configuration");
} else if (options.prompt) {
const openAICommand = new OpenAICommand(openAIApi);
openAICommand
.createSingleChatCompletion(roles.USER, options.prompt)
.then((answer) => {
console.log(answer);
})
.catch((error) => {
console.error("Oops, something went wrong:", error.message);
});
} else if (options.fate) {
const openAICommand = new OpenAICommand(openAIApi);
openAICommand
.tellMeMyFate()
.then((answer) => {
console.log(answer);
})
.catch((error) => {
console.error("Oops, something went wrong:", error.message);
});
} else {
console.error("Please specify a valid command");
program.help();
}