Skip to content

Commit 9ea1e0c

Browse files
committed
initial commit
1 parent 912d83d commit 9ea1e0c

File tree

10 files changed

+695
-0
lines changed

10 files changed

+695
-0
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENAI_API_URL = https://api.openai.com/v1/chat/completions
2+
OPENAI_MODEL = gpt-3.5-turbo
3+
OPENAI_API_KEY = <your-api-key>

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.cache_ggshield
3+
4+
*.log
5+
.pre-commit-config.yaml
6+
.env
7+
.gpt-shell-config.json

index.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env node
2+
3+
import yargs from "yargs";
4+
import { hideBin } from "yargs/helpers";
5+
import { ask, configure } from "./src/main.js";
6+
7+
const isAtLeastOneOptionSpecified = (keys, args) => {
8+
return keys.some((key) => args[key] !== null);
9+
};
10+
11+
const args = yargs(hideBin(process.argv))
12+
.strict(true)
13+
.command(
14+
"ask",
15+
"Send prompt to GPT",
16+
(yargs) => {
17+
yargs
18+
.option("prompt", {
19+
alias: "p",
20+
type: "string",
21+
describe: "Prompt to send to GPT",
22+
demandOption: true,
23+
})
24+
.option("interactive", {
25+
alias: "i",
26+
type: "boolean",
27+
default: false,
28+
describe: "Interactive mode",
29+
});
30+
},
31+
(argv) => {
32+
ask(argv.prompt);
33+
}
34+
)
35+
.command(
36+
"config",
37+
"Configure GPT-Shell",
38+
(yargs) => {
39+
yargs
40+
.option("apikey", {
41+
alias: "k",
42+
type: "string",
43+
default: null,
44+
describe: "API key to use",
45+
})
46+
.option("model", {
47+
alias: "m",
48+
type: "string",
49+
default: null,
50+
describe: "Model to use",
51+
})
52+
.option("url", {
53+
alias: "u",
54+
type: "string",
55+
default: null,
56+
describe: "API endpoint to use",
57+
});
58+
},
59+
(argv) => {
60+
configure(argv);
61+
}
62+
)
63+
.check((argv) => {
64+
if (!isAtLeastOneOptionSpecified(["apikey", "model", "url"], argv)) {
65+
throw new Error("No option specified");
66+
}
67+
return true;
68+
})
69+
.demandCommand(1)
70+
.parse();

0 commit comments

Comments
 (0)