chat methods defined, also test file for library testing

This commit is contained in:
Daniel Avila 2023-02-04 20:49:01 -05:00
parent 7c4e7ab07a
commit 641dcfad73
2 changed files with 35 additions and 6 deletions

View file

@ -1,10 +1,12 @@
require('dotenv').config();
(async () => {
const ask = async (question) => {
const { ChatGPTAPI } = await import('chatgpt');
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_KEY });
const res = await api.sendMessage(question, {
onProgress: (partialRes) => console.log(partialRes.text)
});
return res;
};
// send a message and wait for the response
let res = await api.sendMessage('What is OpenAI?');
console.log(res);
})();
module.exports = { ask };