-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.ts
executable file
·50 lines (38 loc) · 926 Bytes
/
cli.ts
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
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-read
import Ask from "ask";
import { bold, dim, red } from "color";
import { OPENAI_API_KEY } from "/config.ts";
import { Chat } from "~/models/Chat.ts";
async function main() {
console.log(`${dim("---")} ${bold("ChatGPT")} ${dim("---")}`);
if (!OPENAI_API_KEY) {
throw new Error(
"An OpenAI API key is required. Please see README.md for instructions."
);
}
const chat = new Chat();
const ask = new Ask({
prefix: "",
});
while (true) {
const { prompt } = await ask.input({
name: "prompt",
message: ">",
});
if (!prompt) {
continue;
}
const response = await chat.sendMessage(prompt);
console.log(response);
}
}
if (import.meta.main) {
try {
await main();
} catch (err) {
if (err instanceof Error) {
console.error(red(err.message));
}
Deno.exit(1);
}
}