This commit is contained in:
Christopher Cookman 2023-03-08 21:04:05 -07:00
parent 8add79b99e
commit 074158d478
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
2 changed files with 1 additions and 51 deletions

View file

@ -6,6 +6,6 @@
"openai": {
"key": "",
"resetTime": 600000,
"basePrompt": {"role": "system", "name": "Bot", "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible. Knowledge cutoff: 2021, You do not have access to the current date or time. The maximum number of characters in your response is exactly 2000 characters, no more."}
"basePrompt": {"role": "system", "name": "Bot"}
}
}

View file

@ -1,50 +0,0 @@
const config = require("./config.json");
const {
Configuration,
OpenAIApi
} = require("openai");
const openai = new OpenAIApi(new Configuration({
apiKey: config.openai.key
}));
// Take user input via command line
const readline = require("readline").createInterface({
input: process.stdin,
output: process.stdout
});
sessions = {};
// Command line is session 0
sessions[0] = {
messages: []
};
// The ask() function but as a promise
const askPromise = (prompt, session) => {
return new Promise((resolve, reject) => {
// If the session doesn't exist, create it
if (!sessions[session]) {
sessions[session] = {
messages: []
// Ask the user for a prompt
const ask = () => {
readline.question("What would you like to ask the bot? ", async (prompt) => {
// Create a new session
sessions[0].messages.push({
role: "user",
content: prompt
});
await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: sessions[0].messages
}).then((data) => {
sessions[0].messages.push(data.data.choices[0].message);
console.log(`${data.data.choices[0].message.role}: ${data.data.choices[0].message.content}`);
ask();
});
});
};
ask();