Merge pull request #2640 from edk208/release

Adding Block Entropy API endpoints for chat, image, and video generation
This commit is contained in:
Cohee
2024-08-11 16:19:14 +03:00
committed by GitHub
13 changed files with 274 additions and 2 deletions

View File

@ -120,6 +120,7 @@ const default_bias_presets = {
const max_2k = 2047;
const max_4k = 4095;
const max_8k = 8191;
const max_12k = 12287;
const max_16k = 16383;
const max_32k = 32767;
const max_64k = 65535;
@ -186,6 +187,7 @@ export const chat_completion_sources = {
PERPLEXITY: 'perplexity',
GROQ: 'groq',
ZEROONEAI: '01ai',
BLOCKENTROPY: 'blockentropy',
};
const character_names_behavior = {
@ -268,6 +270,7 @@ const default_settings = {
perplexity_model: 'llama-3.1-70b-instruct',
groq_model: 'llama-3.1-70b-versatile',
zerooneai_model: 'yi-large',
blockentropy_model: 'be-70b-base-llama3.1',
custom_model: '',
custom_url: '',
custom_include_body: '',
@ -348,6 +351,7 @@ const oai_settings = {
perplexity_model: 'llama-3.1-70b-instruct',
groq_model: 'llama-3.1-70b-versatile',
zerooneai_model: 'yi-large',
blockentropy_model: 'be-70b-base-llama3.1',
custom_model: '',
custom_url: '',
custom_include_body: '',
@ -1542,6 +1546,8 @@ function getChatCompletionModel() {
return oai_settings.groq_model;
case chat_completion_sources.ZEROONEAI:
return oai_settings.zerooneai_model;
case chat_completion_sources.BLOCKENTROPY:
return oai_settings.blockentropy_model;
default:
throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);
}
@ -1655,6 +1661,23 @@ function saveModelList(data) {
$('#model_01ai_select').val(oai_settings.zerooneai_model).trigger('change');
}
if (oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY) {
$('#model_blockentropy_select').empty();
model_list.forEach((model) => {
$('#model_blockentropy_select').append(
$('<option>', {
value: model.id,
text: model.id,
}));
});
if (!oai_settings.blockentropy_model && model_list.length > 0) {
oai_settings.blockentropy_model = model_list[0].id;
}
$('#model_blockentropy_select').val(oai_settings.blockentropy_model).trigger('change');
}
}
function appendOpenRouterOptions(model_list, groupModels = false, sort = false) {
@ -3015,6 +3038,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.cohere_model = settings.cohere_model ?? default_settings.cohere_model;
oai_settings.perplexity_model = settings.perplexity_model ?? default_settings.perplexity_model;
oai_settings.groq_model = settings.groq_model ?? default_settings.groq_model;
oai_settings.blockentropy_model = settings.blockentropy_model ?? default_settings.blockentropy_model;
oai_settings.zerooneai_model = settings.zerooneai_model ?? default_settings.zerooneai_model;
oai_settings.custom_model = settings.custom_model ?? default_settings.custom_model;
oai_settings.custom_url = settings.custom_url ?? default_settings.custom_url;
@ -3094,6 +3118,7 @@ function loadOpenAISettings(data, settings) {
$('#model_groq_select').val(oai_settings.groq_model);
$(`#model_groq_select option[value="${oai_settings.groq_model}"`).attr('selected', true);
$('#model_01ai_select').val(oai_settings.zerooneai_model);
$('#model_blockentropy_select').val(oai_settings.blockentropy_model);
$('#custom_model_id').val(oai_settings.custom_model);
$('#custom_api_url_text').val(oai_settings.custom_url);
$('#openai_max_context').val(oai_settings.openai_max_context);
@ -3355,6 +3380,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
perplexity_model: settings.perplexity_model,
groq_model: settings.groq_model,
zerooneai_model: settings.zerooneai_model,
blockentropy_model: settings.blockentropy_model,
custom_model: settings.custom_model,
custom_url: settings.custom_url,
custom_include_body: settings.custom_include_body,
@ -3795,6 +3821,7 @@ function onSettingsPresetChange() {
perplexity_model: ['#model_perplexity_select', 'perplexity_model', false],
groq_model: ['#model_groq_select', 'groq_model', false],
zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false],
blockentropy_model: ['#model_blockentropy_select', 'blockentropy_model', false],
custom_model: ['#custom_model_id', 'custom_model', false],
custom_url: ['#custom_api_url_text', 'custom_url', false],
custom_include_body: ['#custom_include_body', 'custom_include_body', false],
@ -4042,6 +4069,12 @@ async function onModelChange() {
oai_settings.zerooneai_model = value;
}
if (value && $(this).is('#model_blockentropy_select')) {
console.log('Block Entropy model changed to', value);
oai_settings.blockentropy_model = value;
$('#blockentropy_model_id').val(value).trigger('input');
}
if (value && $(this).is('#model_custom_select')) {
console.log('Custom model changed to', value);
oai_settings.custom_model = value;
@ -4330,6 +4363,29 @@ async function onModelChange() {
oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
$('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
}
if (oai_settings.chat_completion_source === chat_completion_sources.BLOCKENTROPY) {
if (oai_settings.max_context_unlocked) {
$('#openai_max_context').attr('max', unlocked_max);
}
else if (oai_settings.blockentropy_model.includes('llama3.1')) {
$('#openai_max_context').attr('max', max_16k);
}
else if (oai_settings.blockentropy_model.includes('72b')) {
$('#openai_max_context').attr('max', max_16k);
}
else if (oai_settings.blockentropy_model.includes('120b')) {
$('#openai_max_context').attr('max', max_12k);
}
else {
$('#openai_max_context').attr('max', max_8k);
}
oai_settings.openai_max_context = Math.min(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max')));
$('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
$('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
}
$('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max')));
@ -4537,6 +4593,18 @@ async function onConnectButtonClick(e) {
return;
}
}
if (oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY) {
const api_key_blockentropy = String($('#api_key_blockentropy').val()).trim();
if (api_key_blockentropy.length) {
await writeSecret(SECRET_KEYS.BLOCKENTROPY, api_key_blockentropy);
}
if (!secret_state[SECRET_KEYS.BLOCKENTROPY]) {
console.log('No secret key saved for Block Entropy');
return;
}
}
startStatusLoading();
saveSettingsDebounced();
@ -4588,6 +4656,9 @@ function toggleChatCompletionForms() {
else if (oai_settings.chat_completion_source == chat_completion_sources.CUSTOM) {
$('#model_custom_select').trigger('change');
}
else if (oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY) {
$('#model_blockentropy_select').trigger('change');
}
$('[data-source]').each(function () {
const validSources = $(this).data('source').split(',');
$(this).toggle(validSources.includes(oai_settings.chat_completion_source));
@ -5317,6 +5388,7 @@ $(document).ready(async function () {
$('#model_perplexity_select').on('change', onModelChange);
$('#model_groq_select').on('change', onModelChange);
$('#model_01ai_select').on('change', onModelChange);
$('#model_blockentropy_select').on('change', onModelChange);
$('#model_custom_select').on('change', onModelChange);
$('#settings_preset_openai').on('change', onSettingsPresetChange);
$('#new_oai_preset').on('click', onNewPresetClick);