mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Added block entropy endpoints for chat and image
This commit is contained in:
@ -2427,6 +2427,7 @@
|
||||
<optgroup>
|
||||
<option value="01ai">01.AI (Yi)</option>
|
||||
<option value="ai21">AI21</option>
|
||||
<option value="blockentropy">Block Entropy</option>
|
||||
<option value="claude">Claude</option>
|
||||
<option value="cohere">Cohere</option>
|
||||
<option value="groq">Groq</option>
|
||||
@ -2938,6 +2939,20 @@
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
<form id="blockentropy_form" data-source="blockentropy">
|
||||
<h4 data-i18n="Block Entropy API Key">Block Entropy API Key</h4>
|
||||
<div class="flex-container">
|
||||
<input id="api_key_blockentropy" name="api_key_blockentropy" class="text_pole flex1" maxlength="500" value="" 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_blockentropy"></div>
|
||||
</div>
|
||||
<div data-for="api_key_blockentropy" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you reload the page.">
|
||||
For privacy reasons, your API key will be hidden after you reload the page.
|
||||
</div>
|
||||
<h4 data-i18n="Available Models">Select a Model</h4>
|
||||
<div class="flex-container">
|
||||
<select id="model_blockentropy_select" class="text_pole model_blockentropy_select"></select>
|
||||
</div>
|
||||
</form>
|
||||
<form id="custom_form" data-source="custom">
|
||||
<h4 data-i18n="Custom Endpoint (Base URL)">Custom Endpoint (Base URL)</h4>
|
||||
<div class="flex-container">
|
||||
|
@ -378,6 +378,7 @@ function RA_autoconnect(PrevApi) {
|
||||
|| (secret_state[SECRET_KEYS.PERPLEXITY] && oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY)
|
||||
|| (secret_state[SECRET_KEYS.GROQ] && oai_settings.chat_completion_source == chat_completion_sources.GROQ)
|
||||
|| (secret_state[SECRET_KEYS.ZEROONEAI] && oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI)
|
||||
|| (secret_state[SECRET_KEYS.BLOCKENTROPY] && oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY)
|
||||
|| (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)
|
||||
) {
|
||||
$('#api_button_openai').trigger('click');
|
||||
|
@ -50,6 +50,7 @@ const sources = {
|
||||
drawthings: 'drawthings',
|
||||
pollinations: 'pollinations',
|
||||
stability: 'stability',
|
||||
blockentropy: 'blockentropy',
|
||||
};
|
||||
|
||||
const initiators = {
|
||||
@ -1221,7 +1222,7 @@ async function onModelChange() {
|
||||
extension_settings.sd.model = $('#sd_model').find(':selected').val();
|
||||
saveSettingsDebounced();
|
||||
|
||||
const cloudSources = [sources.horde, sources.novel, sources.openai, sources.togetherai, sources.pollinations, sources.stability];
|
||||
const cloudSources = [sources.horde, sources.novel, sources.openai, sources.togetherai, sources.pollinations, sources.stability, sources.blockentropy];
|
||||
|
||||
if (cloudSources.includes(extension_settings.sd.source)) {
|
||||
return;
|
||||
@ -1433,6 +1434,9 @@ async function loadSamplers() {
|
||||
case sources.stability:
|
||||
samplers = ['N/A'];
|
||||
break;
|
||||
case sources.blockentropy:
|
||||
samplers = ['N/A'];
|
||||
break;
|
||||
}
|
||||
|
||||
for (const sampler of samplers) {
|
||||
@ -1619,6 +1623,9 @@ async function loadModels() {
|
||||
case sources.stability:
|
||||
models = await loadStabilityModels();
|
||||
break;
|
||||
case sources.blockentropy:
|
||||
models = await loadBlockEntropyModels();
|
||||
break;
|
||||
}
|
||||
|
||||
for (const model of models) {
|
||||
@ -1713,6 +1720,26 @@ async function loadTogetherAIModels() {
|
||||
return [];
|
||||
}
|
||||
|
||||
async function loadBlockEntropyModels() {
|
||||
if (!secret_state[SECRET_KEYS.BLOCKENTROPY]) {
|
||||
console.debug('Block Entropy API key is not set.');
|
||||
return [];
|
||||
}
|
||||
|
||||
const result = await fetch('/api/sd/blockentropy/models', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
});
|
||||
console.log(result);
|
||||
if (result.ok) {
|
||||
const data = await result.json();
|
||||
console.log(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
async function loadHordeModels() {
|
||||
const result = await fetch('/api/horde/sd-models', {
|
||||
method: 'POST',
|
||||
@ -1979,6 +2006,9 @@ async function loadSchedulers() {
|
||||
case sources.stability:
|
||||
schedulers = ['N/A'];
|
||||
break;
|
||||
case sources.blockentropy:
|
||||
schedulers = ['N/A'];
|
||||
break;
|
||||
}
|
||||
|
||||
for (const scheduler of schedulers) {
|
||||
@ -2055,6 +2085,9 @@ async function loadVaes() {
|
||||
case sources.stability:
|
||||
vaes = ['N/A'];
|
||||
break;
|
||||
case sources.blockentropy:
|
||||
vaes = ['N/A'];
|
||||
break;
|
||||
}
|
||||
|
||||
for (const vae of vaes) {
|
||||
@ -2583,6 +2616,9 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
|
||||
case sources.stability:
|
||||
result = await generateStabilityImage(prefixedPrompt, negativePrompt, signal);
|
||||
break;
|
||||
case sources.blockentropy:
|
||||
result = await generateBlockEntropyImage(prefixedPrompt, negativePrompt, signal);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!result.data) {
|
||||
@ -2638,6 +2674,31 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) {
|
||||
}
|
||||
}
|
||||
|
||||
async function generateBlockEntropyImage(prompt, negativePrompt, signal) {
|
||||
const result = await fetch('/api/sd/blockentropy/generate', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
signal: signal,
|
||||
body: JSON.stringify({
|
||||
prompt: prompt,
|
||||
negative_prompt: negativePrompt,
|
||||
model: extension_settings.sd.model,
|
||||
steps: extension_settings.sd.steps,
|
||||
width: extension_settings.sd.width,
|
||||
height: extension_settings.sd.height,
|
||||
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
const data = await result.json();
|
||||
return { format: 'png', data: data.images[0] };
|
||||
} else {
|
||||
const text = await result.text();
|
||||
throw new Error(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an image using the Pollinations API.
|
||||
* @param {string} prompt - The main instruction used to guide the image generation.
|
||||
@ -3451,6 +3512,8 @@ function isValidState() {
|
||||
return true;
|
||||
case sources.stability:
|
||||
return secret_state[SECRET_KEYS.STABILITY];
|
||||
case sources.blockentropy:
|
||||
return secret_state[SECRET_KEYS.BLOCKENTROPY];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
<option value="auto">Stable Diffusion Web UI (AUTOMATIC1111)</option>
|
||||
<option value="horde">Stable Horde</option>
|
||||
<option value="togetherai">TogetherAI</option>
|
||||
<option value="blockentropy">Block Entropy</option>
|
||||
</select>
|
||||
<div data-sd-source="auto">
|
||||
<label for="sd_auto_url">SD Web UI URL</label>
|
||||
@ -378,7 +379,7 @@
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div data-sd-source="novel,togetherai,pollinations,comfy,drawthings,vlad,auto,horde,extras,stability" class="marginTop5">
|
||||
<div data-sd-source="novel,togetherai,pollinations,comfy,drawthings,vlad,auto,horde,extras,stability,blockentropy" class="marginTop5">
|
||||
<label for="sd_seed">
|
||||
<span data-i18n="Seed">Seed</span>
|
||||
<small data-i18n="(-1 for random)">(-1 for random)</small>
|
||||
|
@ -185,6 +185,7 @@ export const chat_completion_sources = {
|
||||
PERPLEXITY: 'perplexity',
|
||||
GROQ: 'groq',
|
||||
ZEROONEAI: '01ai',
|
||||
BLOCKENTROPY: 'blockentropy',
|
||||
};
|
||||
|
||||
const character_names_behavior = {
|
||||
@ -267,6 +268,7 @@ const default_settings = {
|
||||
perplexity_model: 'llama-3-70b-instruct',
|
||||
groq_model: 'llama3-70b-8192',
|
||||
zerooneai_model: 'yi-large',
|
||||
blockentropy_model: 'be-70b-base-llama3.1',
|
||||
custom_model: '',
|
||||
custom_url: '',
|
||||
custom_include_body: '',
|
||||
@ -347,6 +349,7 @@ const oai_settings = {
|
||||
perplexity_model: 'llama-3-70b-instruct',
|
||||
groq_model: 'llama3-70b-8192',
|
||||
zerooneai_model: 'yi-large',
|
||||
blockentropy_model: 'be-70b-base-llama3.1',
|
||||
custom_model: '',
|
||||
custom_url: '',
|
||||
custom_include_body: '',
|
||||
@ -1541,6 +1544,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}`);
|
||||
}
|
||||
@ -1654,6 +1659,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) {
|
||||
@ -4037,6 +4059,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;
|
||||
@ -4302,6 +4330,19 @@ 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 {
|
||||
$('#openai_max_context').attr('max', max_32k);
|
||||
}
|
||||
|
||||
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')));
|
||||
|
||||
@ -4509,6 +4550,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();
|
||||
@ -5282,6 +5335,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);
|
||||
|
@ -32,6 +32,7 @@ export const SECRET_KEYS = {
|
||||
ZEROONEAI: 'api_key_01ai',
|
||||
HUGGINGFACE: 'api_key_huggingface',
|
||||
STABILITY: 'api_key_stability',
|
||||
BLOCKENTROPY: 'api_key_blockentropy',
|
||||
};
|
||||
|
||||
const INPUT_MAP = {
|
||||
@ -63,6 +64,7 @@ const INPUT_MAP = {
|
||||
[SECRET_KEYS.FEATHERLESS]: '#api_key_featherless',
|
||||
[SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',
|
||||
[SECRET_KEYS.HUGGINGFACE]: '#api_key_huggingface',
|
||||
[SECRET_KEYS.BLOCKENTROPY]: '#api_key_blockentropy',
|
||||
};
|
||||
|
||||
async function clearSecret() {
|
||||
|
@ -3190,6 +3190,7 @@ function getModelOptions() {
|
||||
{ id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },
|
||||
{ id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },
|
||||
{ id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },
|
||||
{ id: 'model_blockentropy_select', api: 'openai', type: chat_completion_sources.BLOCKENTROPY },
|
||||
{ id: 'model_novel_select', api: 'novel', type: null },
|
||||
{ id: 'horde_model', api: 'koboldhorde', type: null },
|
||||
];
|
||||
|
@ -549,6 +549,15 @@ export function getTokenizerModel() {
|
||||
return yiTokenizer;
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source === chat_completion_sources.BLOCKENTROPY) {
|
||||
if (oai_settings.blockentropy_model.includes('llama3')) {
|
||||
return llama3Tokenizer;
|
||||
}
|
||||
if (oai_settings.blockentropy_model.includes('miqu') || oai_settings.blockentropy_model.includes('mixtral')) {
|
||||
return mistralTokenizer;
|
||||
}
|
||||
}
|
||||
|
||||
// Default to Turbo 3.5
|
||||
return turboTokenizer;
|
||||
}
|
||||
|
@ -195,6 +195,7 @@ const CHAT_COMPLETION_SOURCES = {
|
||||
PERPLEXITY: 'perplexity',
|
||||
GROQ: 'groq',
|
||||
ZEROONEAI: '01ai',
|
||||
BLOCKENTROPY: 'blockentropy',
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@ const API_PERPLEXITY = 'https://api.perplexity.ai';
|
||||
const API_GROQ = 'https://api.groq.com/openai/v1';
|
||||
const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';
|
||||
const API_01AI = 'https://api.01.ai/v1';
|
||||
const API_BLOCKENTROPY = 'https://api.blockentropy.ai/v1';
|
||||
|
||||
/**
|
||||
* Applies a post-processing step to the generated messages.
|
||||
@ -675,6 +676,10 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
|
||||
api_url = API_01AI;
|
||||
api_key_openai = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
|
||||
headers = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.BLOCKENTROPY) {
|
||||
api_url = API_BLOCKENTROPY;
|
||||
api_key_openai = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
|
||||
headers = {};
|
||||
} else {
|
||||
console.log('This chat completion source is not supported yet.');
|
||||
return response_getstatus_openai.status(400).send({ error: true });
|
||||
@ -941,6 +946,11 @@ router.post('/generate', jsonParser, function (request, response) {
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.BLOCKENTROPY) {
|
||||
apiUrl = API_BLOCKENTROPY;
|
||||
apiKey = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
|
||||
headers = {};
|
||||
bodyParams = {};
|
||||
} else {
|
||||
console.log('This chat completion source is not supported yet.');
|
||||
return response.status(400).send({ error: true });
|
||||
|
@ -44,6 +44,7 @@ const SECRET_KEYS = {
|
||||
ZEROONEAI: 'api_key_01ai',
|
||||
HUGGINGFACE: 'api_key_huggingface',
|
||||
STABILITY: 'api_key_stability',
|
||||
BLOCKENTROPY: 'api_key_blockentropy',
|
||||
};
|
||||
|
||||
// These are the keys that are safe to expose, even if allowKeysExposure is false
|
||||
|
@ -8,6 +8,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||
const { jsonParser } = require('../express-common');
|
||||
const { readSecret, SECRET_KEYS } = require('./secrets.js');
|
||||
const FormData = require('form-data');
|
||||
const { scheduler } = require('timers/promises');
|
||||
|
||||
/**
|
||||
* Sanitizes a string.
|
||||
@ -908,10 +909,102 @@ stability.post('/generate', jsonParser, async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
const blockentropy = express.Router();
|
||||
|
||||
blockentropy.post('/models', jsonParser, async (request, response) => {
|
||||
try {
|
||||
const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
|
||||
|
||||
if (!key) {
|
||||
console.log('Block Entropy key not found.');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const modelsResponse = await fetch('https://api.blockentropy.ai/sdapi/v1/schedulers', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${key}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!modelsResponse.ok) {
|
||||
console.log('Block Entropy returned an error.');
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
|
||||
const data = await modelsResponse.json();
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
console.log('Block Entropy returned invalid data.');
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
const models = data.map(x => ({ value: x.name, text: x.name }));
|
||||
return response.send(models);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
blockentropy.post('/generate', jsonParser, async (request, response) => {
|
||||
try {
|
||||
const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
|
||||
|
||||
if (!key) {
|
||||
console.log('Block Entropy key not found.');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
console.log('Block Entropy request:', request.body);
|
||||
|
||||
const result = await fetch('https://api.blockentropy.ai/sdapi/v1/txt2img', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
request_type: 'image-model-inference',
|
||||
prompt: request.body.prompt,
|
||||
negative_prompt: request.body.negative_prompt,
|
||||
height: request.body.height,
|
||||
width: request.body.width,
|
||||
model: request.body.model,
|
||||
steps: request.body.steps,
|
||||
scheduler: request.body.scheduler,
|
||||
n: 1,
|
||||
// Limited to 10000 on playground, works fine with more.
|
||||
seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000),
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${key}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
console.log('Block Entropy returned an error.');
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
|
||||
const data = await result.json();
|
||||
console.log('Block Entropy response:', data);
|
||||
|
||||
//if (data.status !== 'finished') {
|
||||
// console.log('Block Entropy job failed.');
|
||||
// return response.sendStatus(500);
|
||||
//}
|
||||
|
||||
return response.send(data);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.use('/comfy', comfy);
|
||||
router.use('/together', together);
|
||||
router.use('/drawthings', drawthings);
|
||||
router.use('/pollinations', pollinations);
|
||||
router.use('/stability', stability);
|
||||
router.use('/blockentropy', blockentropy);
|
||||
|
||||
module.exports = { router };
|
||||
|
Reference in New Issue
Block a user