-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.js
31 lines (21 loc) · 775 Bytes
/
chat.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 prompt from "prompt-sync"
import { Configuration, OpenAIApi } from "openai"
import * as dotenv from 'dotenv'
import search from "./lib/search.js"
import generateResponse from "./lib/generate.js"
dotenv.config()
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const p = prompt()
let userPrompt = ""
while (true){
console.log("\x1b[36mEnter your prompt for ChatGPT:\n")
userPrompt = p("\x1b[37m")
if(userPrompt == null){ break }
const searchResult = await search(userPrompt)
const generationResult = await generateResponse(userPrompt, searchResult, openai)
console.log("\n\x1b[32mAnswer: \n")
console.log("\x1b[37m"+generationResult + "\n\n")
}