Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
865 B
4
Indexable
Never
const { Configuration, OpenAIApi } = require("openai");

module.exports.run = async (args, api, db, event, input, msgID, senderID, threadID, src, prefix) => {
    if (!(args.length === 0)) {
      try {
        let query = args.join(" ");
        const configuration = new Configuration({
          apiKey: db.openaikey,
        });
  
        const openai = new OpenAIApi(configuration);
          const {data} = await openai.createChatCompletion({
            model: "gpt-3.5-turbo",
            messages: [{"role": "user", "content": query}]
          });
  
        api.sendMessage(data.choices[0].message.content, threadID, msgID);
      } catch (error) {
        api.sendMessage(`⚠️An error has occured!\n${error.message}`)
      }
    } else {
      api.sendMessage(`⚠️Invalid Use Of Command!\n💡Usage: ${prefix}ai query`, threadID, msgID);
    }
}