diff --git a/decai/decai.r2.js b/decai/decai.r2.js index bea9cf9..52dd1a6 100644 --- a/decai/decai.r2.js +++ b/decai/decai.r2.js @@ -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; @@ -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" });