-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (25 loc) · 886 Bytes
/
Copy pathindex.js
File metadata and controls
34 lines (25 loc) · 886 Bytes
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
import readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
const WORKER_URL = process.env.CODEX_WORKER_URL;
if (!WORKER_URL) {
console.log("Missing CODEX_WORKER_URL in .env");
process.exit(1);
}
const rl = readline.createInterface({ input, output });
console.log("Codex Assistant (Node.js Terminal Chat)");
console.log('Type Codex questions. Type "exit" to quit.\n');
while (true) {
const userText = await rl.question("You: ");
if (userText.trim().toLowerCase() === "exit") {
console.log("Good luck with your Codex work 👋");
break;
}
const response = await fetch(WORKER_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: userText })
});
const data = await response.json();
console.log(`Assistant: ${data.reply}\n`);
}
rl.close();