Brrt
This commit is contained in:
parent
8add79b99e
commit
074158d478
|
@ -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"}
|
||||
}
|
||||
}
|
50
gpt-test.js
50
gpt-test.js
|
@ -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();
|
Loading…
Reference in a new issue