Merge e77b16662c
into be7eb8b2b5
This commit is contained in:
commit
a5077b15e4
|
@ -2237,6 +2237,7 @@
|
|||
</a>
|
||||
</div>
|
||||
<h4 data-i18n="Tabby API key">Tabby API key</h4>
|
||||
<small data-i18n="Access TabbyAPI Admin">To access TabbyAPI's model switching, enter an admin key.</small>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_tabby" name="api_key_tabby" class="text_pole flex1 wide100p" maxlength="500" size="35" type="text" autocomplete="off">
|
||||
<div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_tabby">
|
||||
|
@ -2250,6 +2251,14 @@
|
|||
<small data-i18n="Example: 127.0.0.1:5000">Example: http://127.0.0.1:5000</small>
|
||||
<input id="tabby_api_url_text" class="text_pole wide100p" maxlength="500" value="" autocomplete="off" data-server-history="tabby">
|
||||
</div>
|
||||
<div id="tabby_api_model_selection">
|
||||
<h4 data-i18n="Tabby API Model">Tabby API Model</h4>
|
||||
<select id="tabby_api_model">
|
||||
<option data-i18n="-- Connect to the API --">
|
||||
-- Connect to the API --
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div data-tg-type="koboldcpp">
|
||||
<div class="flex-container flexFlowColumn">
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
parseTabbyLogprobs,
|
||||
} from './scripts/textgen-settings.js';
|
||||
|
||||
const { MANCER, TOGETHERAI, OOBA, APHRODITE, OLLAMA, INFERMATICAI, DREAMGEN, OPENROUTER } = textgen_types;
|
||||
const { MANCER, TOGETHERAI, OOBA, APHRODITE, OLLAMA, INFERMATICAI, DREAMGEN, OPENROUTER , TABBY } = textgen_types;
|
||||
|
||||
import {
|
||||
world_info,
|
||||
|
@ -1112,6 +1112,9 @@ async function getStatusTextgen() {
|
|||
} else if (textgen_settings.type === APHRODITE) {
|
||||
loadAphroditeModels(data?.data);
|
||||
online_status = textgen_settings.aphrodite_model;
|
||||
} else if (textgen_settings.type === TABBY) {
|
||||
loadTabbyApiModels(data?.result, data?.data);
|
||||
online_status = textgen_settings.tabby_api_model;
|
||||
} else {
|
||||
online_status = data?.result;
|
||||
}
|
||||
|
@ -9171,11 +9174,35 @@ jQuery(async function () {
|
|||
}
|
||||
}
|
||||
|
||||
if (SECRET_KEYS.TABBY.length) {
|
||||
const endpoint = getTextGenServer();
|
||||
|
||||
if (!endpoint) {
|
||||
console.warn('No endpoint for key check');
|
||||
online_status = 'no_connection';
|
||||
}
|
||||
|
||||
const response = await fetch('/api/backends/text-completions/tabbyapi/verify-key', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({
|
||||
api_server: endpoint,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
if (data?.isAdminKey) {
|
||||
$('#tabby_api_model_selection').show();
|
||||
} else {
|
||||
$('#tabby_api_model_selection').hide();
|
||||
}
|
||||
}
|
||||
|
||||
validateTextGenUrl();
|
||||
startStatusLoading();
|
||||
main_api = 'textgenerationwebui';
|
||||
saveSettingsDebounced();
|
||||
getStatusTextgen();
|
||||
await getStatusTextgen();
|
||||
});
|
||||
|
||||
$('#api_button_novel').on('click', async function (e) {
|
||||
|
|
|
@ -310,6 +310,7 @@ class PresetManager {
|
|||
'togetherai_model',
|
||||
'ollama_model',
|
||||
'aphrodite_model',
|
||||
'tabby_api_model',
|
||||
'server_urls',
|
||||
'type',
|
||||
'custom_model',
|
||||
|
|
|
@ -5,6 +5,7 @@ export const SECRET_KEYS = {
|
|||
MANCER: 'api_key_mancer',
|
||||
APHRODITE: 'api_key_aphrodite',
|
||||
TABBY: 'api_key_tabby',
|
||||
TABBY_ADMIN: 'api_key_admin_tabby',
|
||||
OPENAI: 'api_key_openai',
|
||||
NOVEL: 'api_key_novel',
|
||||
CLAUDE: 'api_key_claude',
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { amount_gen, callPopup, eventSource, event_types, getRequestHeaders, max_context, setGenerationParamsFromPreset } from '../script.js';
|
||||
import {
|
||||
amount_gen,
|
||||
callPopup,
|
||||
eventSource,
|
||||
event_types,
|
||||
getRequestHeaders,
|
||||
max_context,
|
||||
setGenerationParamsFromPreset,
|
||||
token, settings,
|
||||
} from '../script.js';
|
||||
import { textgenerationwebui_settings as textgen_settings, textgen_types } from './textgen-settings.js';
|
||||
import { tokenizers } from './tokenizers.js';
|
||||
import { findSecret, readSecretState, SECRET_KEYS } from './secrets.js';
|
||||
|
||||
let mancerModels = [];
|
||||
let togetherModels = [];
|
||||
let infermaticAIModels = [];
|
||||
let dreamGenModels = [];
|
||||
let aphroditeModels = [];
|
||||
let tabbyApiModels = [];
|
||||
export let openRouterModels = [];
|
||||
|
||||
export async function loadOllamaModels(data) {
|
||||
|
@ -178,6 +189,32 @@ export async function loadAphroditeModels(data) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function loadTabbyApiModels(active, data) {
|
||||
if (!Array.isArray(data)) {
|
||||
console.error('Invalid Tabby API models data', data);
|
||||
return;
|
||||
}
|
||||
|
||||
tabbyApiModels = data;
|
||||
|
||||
if (textgen_settings.tabby_api_model !== active) {
|
||||
textgen_settings.tabby_api_model = active;
|
||||
}
|
||||
|
||||
if (!data.find(x => x.id === textgen_settings.tabby_api_model)) {
|
||||
textgen_settings.tabby_api_model = data[0]?.id || '';
|
||||
}
|
||||
|
||||
$('#tabby_api_model').empty();
|
||||
for (const model of data) {
|
||||
const option = document.createElement('option');
|
||||
option.value = model.id;
|
||||
option.text = model.id;
|
||||
option.selected = model.id === textgen_settings.tabby_api_model;
|
||||
$('#tabby_api_model').append(option);
|
||||
}
|
||||
}
|
||||
|
||||
function onMancerModelSelect() {
|
||||
const modelId = String($('#mancer_model').val());
|
||||
textgen_settings.mancer_model = modelId;
|
||||
|
@ -230,6 +267,37 @@ function onAphroditeModelSelect() {
|
|||
$('#api_button_textgenerationwebui').trigger('click');
|
||||
}
|
||||
|
||||
async function onTabbyApiModelSelect() {
|
||||
const modelId = String($('#tabby_api_model').val());
|
||||
textgen_settings.tabby_api_model = modelId;
|
||||
|
||||
try {
|
||||
const url = String($('#tabby_api_url_text').val()) + 'v1/model/load';
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': token,
|
||||
'x-admin-key': await findSecret(SECRET_KEYS.TABBY),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: textgen_settings.tabby_api_model,
|
||||
}),
|
||||
}).then(
|
||||
(value) => {
|
||||
console.log(value); // Success!
|
||||
},
|
||||
(reason) => {
|
||||
console.error('Could not load model: ' + reason); // Error!
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('Error setting model ', err);
|
||||
}
|
||||
|
||||
$('#api_button_textgenerationwebui').trigger('click');
|
||||
}
|
||||
|
||||
function getMancerModelTemplate(option) {
|
||||
const model = mancerModels.find(x => x.id === option?.element?.value);
|
||||
|
||||
|
@ -324,6 +392,20 @@ function getAphroditeModelTemplate(option) {
|
|||
`));
|
||||
}
|
||||
|
||||
function getTabbyApiModelTemplate(option) {
|
||||
const model = tabbyApiModels.find(x => x.id === option?.element?.value);
|
||||
|
||||
if (!option.id || !model) {
|
||||
return option.text;
|
||||
}
|
||||
|
||||
return $((`
|
||||
<div class="flex-container flexFlowColumn">
|
||||
<div><strong>${DOMPurify.sanitize(model.id)}</strong></div>
|
||||
</div>
|
||||
`));
|
||||
}
|
||||
|
||||
async function downloadOllamaModel() {
|
||||
try {
|
||||
const serverUrl = textgen_settings.server_urls[textgen_types.OLLAMA];
|
||||
|
@ -427,6 +509,7 @@ jQuery(function () {
|
|||
$('#openrouter_model').on('change', onOpenRouterModelSelect);
|
||||
$('#ollama_download_model').on('click', downloadOllamaModel);
|
||||
$('#aphrodite_model').on('change', onAphroditeModelSelect);
|
||||
$('#tabby_api_model').on('change', onTabbyApiModelSelect);
|
||||
|
||||
if (!isMobile()) {
|
||||
$('#mancer_model').select2({
|
||||
|
@ -477,5 +560,12 @@ jQuery(function () {
|
|||
width: '100%',
|
||||
templateResult: getAphroditeModelTemplate,
|
||||
});
|
||||
$('#tabby_api_model').select2({
|
||||
placeholder: 'Select a model',
|
||||
searchInputPlaceholder: 'Search models...',
|
||||
searchInputCssClass: 'text_pole',
|
||||
width: '100%',
|
||||
templateResult: getTabbyApiModelTemplate,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -147,6 +147,7 @@ const settings = {
|
|||
ollama_model: '',
|
||||
openrouter_model: 'openrouter/auto',
|
||||
aphrodite_model: '',
|
||||
tabby_api_model: '',
|
||||
dreamgen_model: 'opus-v1-xl/text',
|
||||
legacy_api: false,
|
||||
sampler_order: KOBOLDCPP_ORDER,
|
||||
|
@ -1119,4 +1120,3 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
|
|||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ const { jsonParser } = require('../../express-common');
|
|||
const { TEXTGEN_TYPES, TOGETHERAI_KEYS, OLLAMA_KEYS, INFERMATICAI_KEYS, OPENROUTER_KEYS, DREAMGEN_KEYS } = require('../../constants');
|
||||
const { forwardFetchResponse, trimV1 } = require('../../util');
|
||||
const { setAdditionalHeaders } = require('../../additional-headers');
|
||||
const { readSecret, SECRET_KEYS } = require('../secrets');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
@ -473,6 +474,42 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
|
|||
}
|
||||
});
|
||||
|
||||
const tabbyapi = express.Router();
|
||||
|
||||
tabbyapi.post('/verify-key', jsonParser, async function (request, response) {
|
||||
try {
|
||||
if (request.body.api_server.indexOf('localhost') !== -1) {
|
||||
request.body.api_server = request.body.api_server.replace('localhost', '127.0.0.1');
|
||||
}
|
||||
|
||||
console.log('Trying to connect to API:', request.body);
|
||||
const baseUrl = trimV1(request.body.api_server);
|
||||
const apiKey = readSecret(SECRET_KEYS.TABBY);
|
||||
|
||||
const fetchResponse = await fetch(`${baseUrl}/v1/auth/permission`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-api-key': apiKey,
|
||||
},
|
||||
timeout: 0,
|
||||
});
|
||||
|
||||
if (!fetchResponse.ok) {
|
||||
console.log('TabbyAPI error:', fetchResponse.status, fetchResponse.statusText);
|
||||
return response.status(500).send({ error: true });
|
||||
}
|
||||
|
||||
const data = await fetchResponse.json();
|
||||
|
||||
return response.send({ 'isAdminKey': data?.permission === 'admin' });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return response.status(500);
|
||||
}
|
||||
});
|
||||
|
||||
llamacpp.post('/props', jsonParser, async function (request, response) {
|
||||
try {
|
||||
if (!request.body.server_url) {
|
||||
|
@ -557,5 +594,6 @@ llamacpp.post('/slots', jsonParser, async function (request, response) {
|
|||
|
||||
router.use('/ollama', ollama);
|
||||
router.use('/llamacpp', llamacpp);
|
||||
router.use('/tabbyapi', tabbyapi);
|
||||
|
||||
module.exports = { router };
|
||||
|
|
Loading…
Reference in New Issue