Create ia.js
Browse files- plugins/ia.js +96 -0
plugins/ia.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import wweb from 'whatsapp-web.js'
|
| 2 |
+
var model ={
|
| 3 |
+
chat:process.env.chat_model,
|
| 4 |
+
imagine:process.env.imagine_model
|
| 5 |
+
}
|
| 6 |
+
function buildResponse(message){
|
| 7 |
+
return {"messages":[message],
|
| 8 |
+
"previewToken":null,
|
| 9 |
+
"codeModelMode":true,
|
| 10 |
+
"agentMode":{
|
| 11 |
+
"mode":true,
|
| 12 |
+
"id":model.chat,
|
| 13 |
+
"name":"CUSTOM"},
|
| 14 |
+
"trendingAgentMode":{},
|
| 15 |
+
"isMicMode":false,
|
| 16 |
+
"isChromeExt":false,
|
| 17 |
+
"githubToken":null,
|
| 18 |
+
"clickedAnswer2":false,
|
| 19 |
+
"clickedAnswer3":false,
|
| 20 |
+
"clickedForceWebSearch":false,
|
| 21 |
+
"visitFromDelta":null
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
}
|
| 26 |
+
function getMessage(content,special,role){
|
| 27 |
+
return {"id":special.generateAlphanumericString(10),
|
| 28 |
+
"content":content,
|
| 29 |
+
"role":(role==undefined)?"user":role
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
async function chat(msg,text,special){
|
| 33 |
+
let response=buildResponse(getMessage(text,special))
|
| 34 |
+
let r=await fetch("https://blackbox.ai/api/chat",{
|
| 35 |
+
method:"post",
|
| 36 |
+
headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.3"},
|
| 37 |
+
body:JSON.stringify(response)
|
| 38 |
+
});
|
| 39 |
+
let co=await r.text();
|
| 40 |
+
await special.delay(5000);
|
| 41 |
+
await msg.reply(co.split("$@$").slice(2).join('$@$'));
|
| 42 |
+
|
| 43 |
+
}
|
| 44 |
+
async function imagine(msg,args,special){
|
| 45 |
+
let seed=special.between(1,100000);
|
| 46 |
+
let prompt=args.shift();
|
| 47 |
+
let negative_prompt=(args.length>0)?args[0]:"";
|
| 48 |
+
const sampler="DPM++ 2M Karras";
|
| 49 |
+
let params={
|
| 50 |
+
new:true,
|
| 51 |
+
model: model.imagine,
|
| 52 |
+
sampler: sampler,
|
| 53 |
+
cfg:13,
|
| 54 |
+
steps:20,
|
| 55 |
+
seed:seed,
|
| 56 |
+
prompt:prompt,
|
| 57 |
+
negative_prompt:negative_prompt
|
| 58 |
+
};
|
| 59 |
+
const url = "https://api.prodia.com/generate?"+new URLSearchParams(params).toString();
|
| 60 |
+
let resp=await fetch(url);
|
| 61 |
+
let response=await resp.json();
|
| 62 |
+
await special.delay(5000);
|
| 63 |
+
let r = await fetch("https://api.prodia.com/job/"+response.job);
|
| 64 |
+
let s=await r.json();
|
| 65 |
+
while(s.status!="succeeded"){
|
| 66 |
+
await special.delay(500);
|
| 67 |
+
r = await fetch("https://api.prodia.com/job/"+response.job);
|
| 68 |
+
s=await r.json();
|
| 69 |
+
}
|
| 70 |
+
const rurl="https://images.prodia.xyz/"+response.job+".png";
|
| 71 |
+
const pic =await wweb.MessageMedia.fromUrl(rurl);
|
| 72 |
+
await special.delay(1000);
|
| 73 |
+
await msg.reply(pic);
|
| 74 |
+
}
|
| 75 |
+
export default function(client,_,special){
|
| 76 |
+
client.on('message_create',async msg=>{
|
| 77 |
+
let texto=msg.body.toString()
|
| 78 |
+
if(!texto.startsWith(special.prefix) || !msg.fromMe) return;
|
| 79 |
+
let args=texto.slice(special.prefix.length).split(" ");
|
| 80 |
+
let command=args.shift();
|
| 81 |
+
args=args.join(" ").split("|");
|
| 82 |
+
if(command=="ia"){
|
| 83 |
+
await chat(msg,args.join('|'),special);
|
| 84 |
+
}else if(command=="imagine"){
|
| 85 |
+
await imagine(msg,args,special);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
});
|
| 91 |
+
return {name:"IA External",
|
| 92 |
+
comandos:[
|
| 93 |
+
{name:"ia",description:"Interactua con una ia",args:["[texto]"]},
|
| 94 |
+
{name:"imagine",description:"Imagina",args:["[prompt]","(negative prompt)"]}
|
| 95 |
+
]}
|
| 96 |
+
}
|