Skip to content

Commit

Permalink
Implement listing models on remote openapi instances
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 21, 2024
1 parent c1876aa commit 5ae84a5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion decai/decai.r2.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ You can write your custom decai commands in your ~/.radare2rc file.
}
break;
case "model":
decaiModel = v;
if (v === "?") {
if (decaiApi.startsWith("openapi")) {
openApiListModels();
}
} else {
decaiModel = v;
}
break;
case "cache":
decaiCache = v === "true" || v == 1;
Expand Down Expand Up @@ -312,6 +318,22 @@ You can write your custom decai commands in your ~/.radare2rc file.
}
return "error invalid response";
}
function openApiListModels(msg, hideprompt) {
const curlcmd = `curl -s ${decaiHost}:${decaiPort}/tags`
const res = r2.syscmds(curlcmd);
try {
const models = JSON.parse(res).models;
const res = [];
for (const model of models) {
res.push(model.name);
}
return res.join("\n");
} catch(e) {
console.error(e);
console.log(res);
}
return "error invalid response";
}
function r2aiOpenAPI2(msg, hideprompt) {
const query = hideprompt? msg: decprompt + ", Transform this pseudocode into " + decaiLanguage + "\n" + msg;
const payload = JSON.stringify({ "prompt": query, "model": "qwen2.5_Coder_1.5B_4bit" });
Expand Down

0 comments on commit 5ae84a5

Please sign in to comment.