feature: implements possibility to update AI model versions for admin
This commit is contained in:
parent
ed5efcccfe
commit
a1c66a2e0b
14 changed files with 479 additions and 95 deletions
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field" id="model">
|
||||
<div class="field" id="model" style="display: flex;">
|
||||
<div class="label label">
|
||||
<label for="model">${_('Model')}</label>
|
||||
</div>
|
||||
|
|
@ -24,6 +24,10 @@
|
|||
<option value="${m}">${m}</option>
|
||||
% endfor
|
||||
</select>
|
||||
|
||||
<button type="button" class="btn btn-primary" id="model_version_button_update" style="display: inline-flex">
|
||||
${_('Update model versions')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="model_version_slot"></div>
|
||||
|
|
@ -76,6 +80,7 @@ import json
|
|||
const $slot = $('#model_version_slot');
|
||||
const $enable = $('#rhodecode_ai_features_enabled');
|
||||
const $form = $('#ai_features_form');
|
||||
const $updateModelsBtn = $('#model_version_button_update');
|
||||
|
||||
function renderVersionField(model) {
|
||||
const versions = MODEL_MAP[model] || [];
|
||||
|
|
@ -83,10 +88,12 @@ import json
|
|||
$slot.empty();
|
||||
|
||||
if (!versions.length) {
|
||||
setAIFieldsActive($enable.is(':checked'));
|
||||
setSaveButtonActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setSaveButtonActive(true);
|
||||
|
||||
const html = `
|
||||
<div class="field" id="model_version">
|
||||
<div class="label label">
|
||||
|
|
@ -98,9 +105,9 @@ import json
|
|||
$slot.append(html);
|
||||
|
||||
const $ver = $('#rhodecode_ai_model_version');
|
||||
for (const v of versions) {
|
||||
const isSelected = (model === SELECTED_MODEL) && (String(v) === String(SELECTED_VERSION));
|
||||
$ver.append(new Option(String(v), String(v), isSelected, isSelected));
|
||||
for (const [key, display_name] of versions) {
|
||||
const isSelected = (model === SELECTED_MODEL) && (String(key) === String(SELECTED_VERSION));
|
||||
$ver.append(new Option(display_name, key, isSelected, isSelected));
|
||||
}
|
||||
|
||||
if (!$ver.find('option:selected').length && versions.length) {
|
||||
|
|
@ -113,6 +120,12 @@ import json
|
|||
setAIFieldsActive($enable.is(':checked'));
|
||||
}
|
||||
|
||||
function setSaveButtonActive(enable) {
|
||||
$('.buttons')
|
||||
.find('input, button')
|
||||
.prop('disabled', !enable);
|
||||
}
|
||||
|
||||
function setAIFieldsActive(enabled) {
|
||||
const $affectedFields = $('.fields .field').not('#ai-features-toggle');
|
||||
|
||||
|
|
@ -147,6 +160,57 @@ import json
|
|||
setAIFieldsActive(this.checked);
|
||||
});
|
||||
|
||||
$updateModelsBtn.click(function () {
|
||||
const $apiKey = $('#rhodecode_ai_api_key input');
|
||||
|
||||
if (!$apiKey.val()) {
|
||||
$.Topic('/notifications').publish({
|
||||
message: {
|
||||
message: "API key required to update model versions.",
|
||||
level: "warning",
|
||||
force: true
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const url = "${h.route_path('admin_settings_ai_update_models')}";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: {
|
||||
'rhodecode_ai_model': $model.val(),
|
||||
'rhodecode_ai_api_key': $apiKey.val(),
|
||||
'rhodecode_ai_features_enabled': $enable.is(':checked')
|
||||
},
|
||||
success: function (response) {
|
||||
$.Topic('/notifications').publish({
|
||||
message: {
|
||||
message: response["message"],
|
||||
level: response["message_category"],
|
||||
force: true
|
||||
}
|
||||
});
|
||||
|
||||
if (Array.isArray(response["versions"]) && response["versions"].length !== 0) {
|
||||
MODEL_MAP[$model.val()] = response["versions"];
|
||||
renderVersionField($model.val());
|
||||
}
|
||||
},
|
||||
error: function (data, textStatus, errorThrown) {
|
||||
console.log(data);
|
||||
$.Topic('/notifications').publish({
|
||||
message: {
|
||||
message: "Error while updating models entry.\nError code {0} ({1}). URL: {2}".format(data.status, data.statusText, url),
|
||||
level: "error",
|
||||
force: true
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$form.submit(function () {
|
||||
let $f = $(this);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue