UNPKG

@hyperbytes/wappler-chatgpt

Version:

interface with ChatGPT API

24 lines 764 B
exports.chatGPT2 = async function (options) { options = this.parse(options); if (options.service === undefined) { chatservice = 'gpt-3.5-turbo'; } else { chatservice = options.service; } require("dotenv").config(); const OpenAI = require("openai"); const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const getchat = async () => { const chatCompletion = await openai.chat.completions.create({ model: chatservice, messages: [{ "role": "user", "content": options.chatinstruction }], max_tokens: options.max_tokens }); return chatCompletion.choices[0].message.content; } console.log(chatservice); return getchat(); }