[feature] Add ai models tab

This commit is contained in:
Sergey Konovalov
2025-05-29 02:28:45 +03:00
parent 875350bb9d
commit 04b234be2e
9 changed files with 531 additions and 117 deletions

View File

@ -81,6 +81,7 @@ const sandbox = {
connectionAndInactivity: cfgAiApiTimeout,
wholeCycle: cfgAiApiTimeout
};
//console.log("fetch", url, options);
return utils.httpRequest(
sandbox.ctx,
method,
@ -130,7 +131,7 @@ function loadInternalProviders() {
const providerCode = fs.readFileSync(providerPath, 'utf8');
try {
sandbox.ctx.logger.debug(`Loading provider ${file}:`);
//sandbox.ctx.logger.debug(`Loading provider ${file}:`);
let content = "(function(){\n" + providerCode + "\nreturn new Provider();})();";
// Execute provider code in sandbox
let provider = vm.runInNewContext(content, sandbox, {
@ -154,10 +155,10 @@ function loadInternalProviders() {
*/
function fillConfigObjects() {
AI.Models = cfgAiApiModels;
for (let i in cfgAiApiActions)
for(let i = 0; i < cfgAiApiActions.length; i++)
{
if (AI.Actions[i] && cfgAiApiActions[i].model) {
AI.Actions[i].model = cfgAiApiActions[i].model;
if (cfgAiApiActions[i].model && AI.Actions[cfgAiApiActions[i].id]) {
AI.Actions[cfgAiApiActions[i].id].model = cfgAiApiActions[i].model;
}
}
}

View File

@ -362,6 +362,9 @@ async function requestModels(req, res) {
try {
await ctx.initTenantCache();
let body = JSON.parse(req.body);
if (body.key && AI.Providers[body.name]) {
AI.Providers[body.name].key = body.key;
}
let models = await AI.getModels(body);
res.json(models);
} catch (error) {