Skip to content

Commit

Permalink
Use r2.syscmds instead of r2.cmd("!") in decai
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Sep 6, 2024
1 parent 44b2102 commit 8df5b36
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions decai/decai.r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,15 @@ You can also make r2ai -w talk to an 'r2ai-server' using this line:
}
]
});
const curlcmd = `'!curl -o .txt -s https://api.anthropic.com/v1/messages
const curlcmd = `curl -s https://api.anthropic.com/v1/messages
-H "Content-Type: application/json"
-H "anthropic-version: 2023-06-01"
-H "x-api-key: ${claudeKey}"
-d '${payload}'`.replace(/\n/g, "");
if (decaiDebug) {
console.log(curlcmd);
}
r2.cmd(curlcmd);
const res = r2.cmd("cat .txt");
const res = r2.syscmds(curlcmd);
try {
return JSON.parse(res).content[0].text;
} catch(e) {
Expand All @@ -177,15 +176,14 @@ You can also make r2ai -w talk to an 'r2ai-server' using this line:
}
]
});
const curlcmd = `'!curl -s -o .decai.txt https://api.openai.com/v1/chat/completions
const curlcmd = `curl -s https://api.openai.com/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer ${openaiKey}"
-d '${payload}' #`.replace(/\n/g, "");
if (decaiDebug) {
console.log(curlcmd);
}
r2.cmd0(curlcmd);
const res = r2.cmd("cat .decai.txt");
const res = r2.syscmds(curlcmd);
try {
return JSON.parse(res).choices[0].message.content;
} catch(e) {
Expand All @@ -196,14 +194,13 @@ You can also make r2ai -w talk to an 'r2ai-server' using this line:
}
function r2aiOpenAPI(msg) {
const payload = JSON.stringify({ "prompt": decprompt + ", Output in " + decaiLanguage + "\n" + msg });
const curlcmd = `'!curl -s -o .decai.txt ${decaiHost}:${decaiPort}/completion
const curlcmd = `curl -s ${decaiHost}:${decaiPort}/completion
-H "Content-Type: application/json"
-d '${payload}' #`.replace(/\n/g, "");
if (decaiDebug) {
console.log(curlcmd);
}
r2.cmd0(curlcmd);
const res = r2.cmd("cat .decai.txt");
const res = r2.syscmds(curlcmd);
try {
return JSON.parse(res).content;
} catch(e) {
Expand All @@ -228,12 +225,11 @@ You can also make r2ai -w talk to an 'r2ai-server' using this line:
const q = queryText.startsWith("-")? queryText: ["-i", fileName, queryText].join(" ");
const host = decaiHost + ":" + decaiPort + "/cmd"; // "http://localhost:8080/cmd";
const ss = q.replace(/ /g, "%20").replace(/'/g, "\\'");
const cmd = '\'!curl -s "' + host + '/' + ss + '" > .pdc.txt || echo Cannot curl, use r2ai-server or r2ai -w #';
const cmd = 'curl -s "' + host + '/' + ss + '" || echo Cannot curl, use r2ai-server or r2ai -w #';
if (decaiDebug) {
console.error(cmd);
}
r2.cmd0(cmd);
return r2.cmd('cat .pdc.txt');
return r2.syscmds(cmd);
}
if (fileData === "" || queryText.startsWith("-")) { // -i
return "";
Expand Down

0 comments on commit 8df5b36

Please sign in to comment.