Advertisement
samiroexpikachu

Claude

Mar 11th, 2024 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  const axios = require('axios');
  2. const tracker = {};
  3.  
  4. const config = {
  5.   name: "claude",
  6.   version: "1.0",
  7.   author: "Samir Œ",
  8.   countDown: 5,
  9.   role: 0,
  10.   longDescription: "Claude3 AI",
  11.   category: "𝗔𝗜",
  12.   guide: { en: "{pn} <query>" },
  13. };
  14.  
  15. const apiKey = ""; // add your  API key
  16.  
  17. const onStart = async function ({ message, event, args, usersData }) {
  18.   const prompt = args.join(' ');
  19.   const userName = await usersData.getName(event.senderID);
  20.   const userID = event.senderID;
  21.  
  22.   if (!args[0]) return message.reply('Please enter a query.');
  23.  
  24.   if (args[0] === 'clear') {
  25.     clearHistory();
  26.     const c = await clean(userID);
  27.     if (c) return message.reply('Conversation history cleared.');
  28.   }
  29.  
  30.   await claudeAI(prompt, userID, message, userName, config.name.toLowerCase());
  31. };
  32.  
  33. const onReply = async function ({ Reply, message, event, args, getLang, usersData }) {
  34.   const { author } = Reply;
  35.   if (author !== event.senderID) return;
  36.   const prompt = args.join(' ');
  37.   const userID = event.senderID;
  38.   const userName = await usersData.getName(event.senderID);
  39.   await claudeAI(prompt, userID, message, userName, config.name.toLowerCase());
  40. };
  41.  
  42. const clearHistory = function () {
  43.   global.GoatBot.onReply.clear();
  44. };
  45.  
  46. async function clean(userID) {
  47.   if (tracker[userID]) {
  48.     delete tracker[userID];
  49.     return true;
  50.   }
  51.   return false;
  52. }
  53.  
  54. async function claudeAI(text, userID, message, userName, commandName) {
  55.   if (!tracker[userID]) {
  56.     tracker[userID] = `${userName}.\n`;
  57.   }
  58.   tracker[userID] += `${text}.\n`;
  59.  
  60.   try {
  61.     const query = `- Current prompt: ${text}\n\n - Conversation:\n${tracker[userID]}\n`;
  62.     const apiUrl = `https://apis-samir.onrender.com/Claude3?prompt=${encodeURIComponent(query)}&apiKey=${apiKey}`;
  63.     const response = await axios.get(apiUrl, {
  64.       headers: {
  65.         'Content-Type': 'application/json',
  66.       },
  67.     });
  68.  
  69.     const resultContent = response.data.content.text;
  70.     tracker[userID] += `${resultContent}`;
  71.     await message.reply(resultContent, (error, info) => {
  72.       global.GoatBot.onReply.set(info.messageID, {
  73.         commandName: commandName, author: userID
  74.       });
  75.     });
  76.   } catch (error) {
  77.     console.error(error);
  78.     message.reply("An error occurred.");
  79.   }
  80. }
  81.  
  82. //Inspired from Rehat Mistral cmd
  83.  
  84. module.exports = {
  85.   config,
  86.   onStart,
  87.   onReply,
  88. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement