Skip to content

Commit

Permalink
Fixes for the r2ai r2papi
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 7, 2023
1 parent 7a230ef commit 987adc2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
28 changes: 24 additions & 4 deletions typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,15 @@ class R2AI {
available : boolean = false;
model : string = "";
constructor (num, model) {
this.available = r2.call(`r2ai -h`).trim() !== "";
this.available = r2.cmd('r2ai -h').trim() !== "";
if (this.available) {
r2.call(`r2ai -n ${num}`)
if (num) {
r2.call(`r2ai -n ${num}`)
}
// r2.call('r2ai -e DEBUG=1')
this.model = model;
if (model) {
this.model = model;
}
} else {
console.error("ERROR: r2ai is not installed");
}
Expand All @@ -1010,11 +1014,27 @@ class R2AI {
r2.call(`r2ai -r ${msg}`)
}
}
setModel(modelName) {
if (this.available) {
r2.call(`r2ai -m ${this.model}`)
}
}
getModel() {
if (this.available) {
return r2.call("r2ai -m");
}
return this.model;
}
listModels() {
if (this.available) {
return r2.call("r2ai -M").trim().split(/\n/g);
}
return [];
}
query(msg) {
if (!this.available || msg == '') {
return '';
}
r2.call(`r2ai -m ${this.model}`)
const fmsg = msg.trim().replace(/\n/g, '.');
return r2.call(`r2ai ${fmsg}`)
}
Expand Down
4 changes: 2 additions & 2 deletions typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2papi",
"version": "0.2.4",
"version": "0.2.5",
"description": "r2api on top of r2pipe for typescript and js",
"author": "",
"homepage": "http://www.radare.org",
Expand Down

0 comments on commit 987adc2

Please sign in to comment.