Added block entropy endpoints for chat and image

b9857eb315553616b66aa5215eaa267f37704994

Edward Kim <edwardkim.ek@gmail.com>

12 files changed, +253 -2Ignore whitespace
public/index.html+15 -0
@@ -2427,6 +2427,7 @@
2427 <optgroup>2427 <optgroup>
2428 <option value="01ai">01.AI (Yi)</option>2428 <option value="01ai">01.AI (Yi)</option>
2429 <option value="ai21">AI21</option>2429 <option value="ai21">AI21</option>
2430 <option value="blockentropy">Block Entropy</option>
2430 <option value="claude">Claude</option>2431 <option value="claude">Claude</option>
2431 <option value="cohere">Cohere</option>2432 <option value="cohere">Cohere</option>
2432 <option value="groq">Groq</option>2433 <option value="groq">Groq</option>
@@ -2938,6 +2939,20 @@
2938 </select>2939 </select>
2939 </div>2940 </div>
2940 </form>2941 </form>
2942 <form id="blockentropy_form" data-source="blockentropy">
2943 <h4 data-i18n="Block Entropy API Key">Block Entropy API Key</h4>
2944 <div class="flex-container">
2945 <input id="api_key_blockentropy" name="api_key_blockentropy" class="text_pole flex1" maxlength="500" value="" type="text" autocomplete="off">
2946 <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>
2947 </div>
2948 <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.">
2949 For privacy reasons, your API key will be hidden after you reload the page.
2950 </div>
2951 <h4 data-i18n="Available Models">Select a Model</h4>
2952 <div class="flex-container">
2953 <select id="model_blockentropy_select" class="text_pole model_blockentropy_select"></select>
2954 </div>
2955 </form>
2941 <form id="custom_form" data-source="custom">2956 <form id="custom_form" data-source="custom">
2942 <h4 data-i18n="Custom Endpoint (Base URL)">Custom Endpoint (Base URL)</h4>2957 <h4 data-i18n="Custom Endpoint (Base URL)">Custom Endpoint (Base URL)</h4>
2943 <div class="flex-container">2958 <div class="flex-container">
public/scripts/RossAscends-mods.js+1 -0
@@ -378,6 +378,7 @@ function RA_autoconnect(PrevApi) {
378 || (secret_state[SECRET_KEYS.PERPLEXITY] && oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY)378 || (secret_state[SECRET_KEYS.PERPLEXITY] && oai_settings.chat_completion_source == chat_completion_sources.PERPLEXITY)
379 || (secret_state[SECRET_KEYS.GROQ] && oai_settings.chat_completion_source == chat_completion_sources.GROQ)379 || (secret_state[SECRET_KEYS.GROQ] && oai_settings.chat_completion_source == chat_completion_sources.GROQ)
380 || (secret_state[SECRET_KEYS.ZEROONEAI] && oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI)380 || (secret_state[SECRET_KEYS.ZEROONEAI] && oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI)
381 || (secret_state[SECRET_KEYS.BLOCKENTROPY] && oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY)
381 || (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)382 || (isValidUrl(oai_settings.custom_url) && oai_settings.chat_completion_source == chat_completion_sources.CUSTOM)
382 ) {383 ) {
383 $('#api_button_openai').trigger('click');384 $('#api_button_openai').trigger('click');
public/scripts/extensions/stable-diffusion/index.js+64 -1
@@ -50,6 +50,7 @@ const sources = {
50 drawthings: 'drawthings',50 drawthings: 'drawthings',
51 pollinations: 'pollinations',51 pollinations: 'pollinations',
52 stability: 'stability',52 stability: 'stability',
53 blockentropy: 'blockentropy',
53};54};
5455
55const initiators = {56const initiators = {
@@ -1221,7 +1222,7 @@ async function onModelChange() {
1221 extension_settings.sd.model = $('#sd_model').find(':selected').val();1222 extension_settings.sd.model = $('#sd_model').find(':selected').val();
1222 saveSettingsDebounced();1223 saveSettingsDebounced();
12231224
1224 const cloudSources = [sources.horde, sources.novel, sources.openai, sources.togetherai, sources.pollinations, sources.stability];1225 const cloudSources = [sources.horde, sources.novel, sources.openai, sources.togetherai, sources.pollinations, sources.stability, sources.blockentropy];
12251226
1226 if (cloudSources.includes(extension_settings.sd.source)) {1227 if (cloudSources.includes(extension_settings.sd.source)) {
1227 return;1228 return;
@@ -1433,6 +1434,9 @@ async function loadSamplers() {
1433 case sources.stability:1434 case sources.stability:
1434 samplers = ['N/A'];1435 samplers = ['N/A'];
1435 break;1436 break;
1437 case sources.blockentropy:
1438 samplers = ['N/A'];
1439 break;
1436 }1440 }
14371441
1438 for (const sampler of samplers) {1442 for (const sampler of samplers) {
@@ -1619,6 +1623,9 @@ async function loadModels() {
1619 case sources.stability:1623 case sources.stability:
1620 models = await loadStabilityModels();1624 models = await loadStabilityModels();
1621 break;1625 break;
1626 case sources.blockentropy:
1627 models = await loadBlockEntropyModels();
1628 break;
1622 }1629 }
16231630
1624 for (const model of models) {1631 for (const model of models) {
@@ -1713,6 +1720,26 @@ async function loadTogetherAIModels() {
1713 return [];1720 return [];
1714}1721}
17151722
1723async function loadBlockEntropyModels() {
1724 if (!secret_state[SECRET_KEYS.BLOCKENTROPY]) {
1725 console.debug('Block Entropy API key is not set.');
1726 return [];
1727 }
1728
1729 const result = await fetch('/api/sd/blockentropy/models', {
1730 method: 'POST',
1731 headers: getRequestHeaders(),
1732 });
1733 console.log(result);
1734 if (result.ok) {
1735 const data = await result.json();
1736 console.log(data);
1737 return data;
1738 }
1739
1740 return [];
1741}
1742
1716async function loadHordeModels() {1743async function loadHordeModels() {
1717 const result = await fetch('/api/horde/sd-models', {1744 const result = await fetch('/api/horde/sd-models', {
1718 method: 'POST',1745 method: 'POST',
@@ -1979,6 +2006,9 @@ async function loadSchedulers() {
1979 case sources.stability:2006 case sources.stability:
1980 schedulers = ['N/A'];2007 schedulers = ['N/A'];
1981 break;2008 break;
2009 case sources.blockentropy:
2010 schedulers = ['N/A'];
2011 break;
1982 }2012 }
19832013
1984 for (const scheduler of schedulers) {2014 for (const scheduler of schedulers) {
@@ -2055,6 +2085,9 @@ async function loadVaes() {
2055 case sources.stability:2085 case sources.stability:
2056 vaes = ['N/A'];2086 vaes = ['N/A'];
2057 break;2087 break;
2088 case sources.blockentropy:
2089 vaes = ['N/A'];
2090 break;
2058 }2091 }
20592092
2060 for (const vae of vaes) {2093 for (const vae of vaes) {
@@ -2583,6 +2616,9 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
2583 case sources.stability:2616 case sources.stability:
2584 result = await generateStabilityImage(prefixedPrompt, negativePrompt, signal);2617 result = await generateStabilityImage(prefixedPrompt, negativePrompt, signal);
2585 break;2618 break;
2619 case sources.blockentropy:
2620 result = await generateBlockEntropyImage(prefixedPrompt, negativePrompt, signal);
2621 break;
2586 }2622 }
25872623
2588 if (!result.data) {2624 if (!result.data) {
@@ -2638,6 +2674,31 @@ async function generateTogetherAIImage(prompt, negativePrompt, signal) {
2638 }2674 }
2639}2675}
26402676
2677async function generateBlockEntropyImage(prompt, negativePrompt, signal) {
2678 const result = await fetch('/api/sd/blockentropy/generate', {
2679 method: 'POST',
2680 headers: getRequestHeaders(),
2681 signal: signal,
2682 body: JSON.stringify({
2683 prompt: prompt,
2684 negative_prompt: negativePrompt,
2685 model: extension_settings.sd.model,
2686 steps: extension_settings.sd.steps,
2687 width: extension_settings.sd.width,
2688 height: extension_settings.sd.height,
2689 seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
2690 }),
2691 });
2692
2693 if (result.ok) {
2694 const data = await result.json();
2695 return { format: 'png', data: data.images[0] };
2696 } else {
2697 const text = await result.text();
2698 throw new Error(text);
2699 }
2700}
2701
2641/**2702/**
2642 * Generates an image using the Pollinations API.2703 * Generates an image using the Pollinations API.
2643 * @param {string} prompt - The main instruction used to guide the image generation.2704 * @param {string} prompt - The main instruction used to guide the image generation.
@@ -3451,6 +3512,8 @@ function isValidState() {
3451 return true;3512 return true;
3452 case sources.stability:3513 case sources.stability:
3453 return secret_state[SECRET_KEYS.STABILITY];3514 return secret_state[SECRET_KEYS.STABILITY];
3515 case sources.blockentropy:
3516 return secret_state[SECRET_KEYS.BLOCKENTROPY];
3454 }3517 }
3455}3518}
34563519
public/scripts/extensions/stable-diffusion/settings.html+2 -1
@@ -48,6 +48,7 @@
48 <option value="auto">Stable Diffusion Web UI (AUTOMATIC1111)</option>48 <option value="auto">Stable Diffusion Web UI (AUTOMATIC1111)</option>
49 <option value="horde">Stable Horde</option>49 <option value="horde">Stable Horde</option>
50 <option value="togetherai">TogetherAI</option>50 <option value="togetherai">TogetherAI</option>
51 <option value="blockentropy">Block Entropy</option>
51 </select>52 </select>
52 <div data-sd-source="auto">53 <div data-sd-source="auto">
53 <label for="sd_auto_url">SD Web UI URL</label>54 <label for="sd_auto_url">SD Web UI URL</label>
@@ -378,7 +379,7 @@
378 </label>379 </label>
379 </div>380 </div>
380381
381 <div data-sd-source="novel,togetherai,pollinations,comfy,drawthings,vlad,auto,horde,extras,stability" class="marginTop5">382 <div data-sd-source="novel,togetherai,pollinations,comfy,drawthings,vlad,auto,horde,extras,stability,blockentropy" class="marginTop5">
382 <label for="sd_seed">383 <label for="sd_seed">
383 <span data-i18n="Seed">Seed</span>384 <span data-i18n="Seed">Seed</span>
384 <small data-i18n="(-1 for random)">(-1 for random)</small>385 <small data-i18n="(-1 for random)">(-1 for random)</small>
public/scripts/openai.js+54 -0
@@ -185,6 +185,7 @@ export const chat_completion_sources = {
185 PERPLEXITY: 'perplexity',185 PERPLEXITY: 'perplexity',
186 GROQ: 'groq',186 GROQ: 'groq',
187 ZEROONEAI: '01ai',187 ZEROONEAI: '01ai',
188 BLOCKENTROPY: 'blockentropy',
188};189};
189190
190const character_names_behavior = {191const character_names_behavior = {
@@ -267,6 +268,7 @@ const default_settings = {
267 perplexity_model: 'llama-3-70b-instruct',268 perplexity_model: 'llama-3-70b-instruct',
268 groq_model: 'llama3-70b-8192',269 groq_model: 'llama3-70b-8192',
269 zerooneai_model: 'yi-large',270 zerooneai_model: 'yi-large',
271 blockentropy_model: 'be-70b-base-llama3.1',
270 custom_model: '',272 custom_model: '',
271 custom_url: '',273 custom_url: '',
272 custom_include_body: '',274 custom_include_body: '',
@@ -347,6 +349,7 @@ const oai_settings = {
347 perplexity_model: 'llama-3-70b-instruct',349 perplexity_model: 'llama-3-70b-instruct',
348 groq_model: 'llama3-70b-8192',350 groq_model: 'llama3-70b-8192',
349 zerooneai_model: 'yi-large',351 zerooneai_model: 'yi-large',
352 blockentropy_model: 'be-70b-base-llama3.1',
350 custom_model: '',353 custom_model: '',
351 custom_url: '',354 custom_url: '',
352 custom_include_body: '',355 custom_include_body: '',
@@ -1541,6 +1544,8 @@ function getChatCompletionModel() {
1541 return oai_settings.groq_model;1544 return oai_settings.groq_model;
1542 case chat_completion_sources.ZEROONEAI:1545 case chat_completion_sources.ZEROONEAI:
1543 return oai_settings.zerooneai_model;1546 return oai_settings.zerooneai_model;
1547 case chat_completion_sources.BLOCKENTROPY:
1548 return oai_settings.blockentropy_model;
1544 default:1549 default:
1545 throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);1550 throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);
1546 }1551 }
@@ -1654,6 +1659,23 @@ function saveModelList(data) {
16541659
1655 $('#model_01ai_select').val(oai_settings.zerooneai_model).trigger('change');1660 $('#model_01ai_select').val(oai_settings.zerooneai_model).trigger('change');
1656 }1661 }
1662
1663 if (oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY) {
1664 $('.model_blockentropy_select').empty();
1665 model_list.forEach((model) => {
1666 $('.model_blockentropy_select').append(
1667 $('<option>', {
1668 value: model.id,
1669 text: model.id,
1670 }));
1671 });
1672
1673 if (!oai_settings.blockentropy_model && model_list.length > 0) {
1674 oai_settings.blockentropy_model = model_list[0].id;
1675 }
1676
1677 $('#model_blockentropy_select').val(oai_settings.blockentropy_model).trigger('change');
1678 }
1657}1679}
16581680
1659function appendOpenRouterOptions(model_list, groupModels = false, sort = false) {1681function appendOpenRouterOptions(model_list, groupModels = false, sort = false) {
@@ -4037,6 +4059,12 @@ async function onModelChange() {
4037 oai_settings.zerooneai_model = value;4059 oai_settings.zerooneai_model = value;
4038 }4060 }
40394061
4062 if (value && $(this).is('#model_blockentropy_select')) {
4063 console.log('Block Entropy model changed to', value);
4064 oai_settings.blockentropy_model = value;
4065 $('#blockentropy_model_id').val(value).trigger('input');
4066 }
4067
4040 if (value && $(this).is('#model_custom_select')) {4068 if (value && $(this).is('#model_custom_select')) {
4041 console.log('Custom model changed to', value);4069 console.log('Custom model changed to', value);
4042 oai_settings.custom_model = value;4070 oai_settings.custom_model = value;
@@ -4302,6 +4330,19 @@ async function onModelChange() {
4302 oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);4330 oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
4303 $('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');4331 $('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
4304 }4332 }
4333 if (oai_settings.chat_completion_source === chat_completion_sources.BLOCKENTROPY) {
4334 if (oai_settings.max_context_unlocked) {
4335 $('#openai_max_context').attr('max', unlocked_max);
4336 } else {
4337 $('#openai_max_context').attr('max', max_32k);
4338 }
4339
4340 oai_settings.openai_max_context = Math.min(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max')));
4341 $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
4342
4343 oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
4344 $('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
4345 }
43054346
4306 $('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max')));4347 $('#openai_max_context_counter').attr('max', Number($('#openai_max_context').attr('max')));
43074348
@@ -4509,6 +4550,18 @@ async function onConnectButtonClick(e) {
4509 return;4550 return;
4510 }4551 }
4511 }4552 }
4553 if (oai_settings.chat_completion_source == chat_completion_sources.BLOCKENTROPY) {
4554 const api_key_blockentropy = String($('#api_key_blockentropy').val()).trim();
4555
4556 if (api_key_blockentropy.length) {
4557 await writeSecret(SECRET_KEYS.BLOCKENTROPY, api_key_blockentropy);
4558 }
4559
4560 if (!secret_state[SECRET_KEYS.BLOCKENTROPY]) {
4561 console.log('No secret key saved for Block Entropy');
4562 return;
4563 }
4564 }
45124565
4513 startStatusLoading();4566 startStatusLoading();
4514 saveSettingsDebounced();4567 saveSettingsDebounced();
@@ -5282,6 +5335,7 @@ $(document).ready(async function () {
5282 $('#model_perplexity_select').on('change', onModelChange);5335 $('#model_perplexity_select').on('change', onModelChange);
5283 $('#model_groq_select').on('change', onModelChange);5336 $('#model_groq_select').on('change', onModelChange);
5284 $('#model_01ai_select').on('change', onModelChange);5337 $('#model_01ai_select').on('change', onModelChange);
5338 $('#model_blockentropy_select').on('change', onModelChange);
5285 $('#model_custom_select').on('change', onModelChange);5339 $('#model_custom_select').on('change', onModelChange);
5286 $('#settings_preset_openai').on('change', onSettingsPresetChange);5340 $('#settings_preset_openai').on('change', onSettingsPresetChange);
5287 $('#new_oai_preset').on('click', onNewPresetClick);5341 $('#new_oai_preset').on('click', onNewPresetClick);
public/scripts/secrets.js+2 -0
@@ -32,6 +32,7 @@ export const SECRET_KEYS = {
32 ZEROONEAI: 'api_key_01ai',32 ZEROONEAI: 'api_key_01ai',
33 HUGGINGFACE: 'api_key_huggingface',33 HUGGINGFACE: 'api_key_huggingface',
34 STABILITY: 'api_key_stability',34 STABILITY: 'api_key_stability',
35 BLOCKENTROPY: 'api_key_blockentropy',
35};36};
3637
37const INPUT_MAP = {38const INPUT_MAP = {
@@ -63,6 +64,7 @@ const INPUT_MAP = {
63 [SECRET_KEYS.FEATHERLESS]: '#api_key_featherless',64 [SECRET_KEYS.FEATHERLESS]: '#api_key_featherless',
64 [SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',65 [SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',
65 [SECRET_KEYS.HUGGINGFACE]: '#api_key_huggingface',66 [SECRET_KEYS.HUGGINGFACE]: '#api_key_huggingface',
67 [SECRET_KEYS.BLOCKENTROPY]: '#api_key_blockentropy',
66};68};
6769
68async function clearSecret() {70async function clearSecret() {
public/scripts/slash-commands.js+1 -0
@@ -3190,6 +3190,7 @@ function getModelOptions() {
3190 { id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },3190 { id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },
3191 { id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },3191 { id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },
3192 { id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },3192 { id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },
3193 { id: 'model_blockentropy_select', api: 'openai', type: chat_completion_sources.BLOCKENTROPY },
3193 { id: 'model_novel_select', api: 'novel', type: null },3194 { id: 'model_novel_select', api: 'novel', type: null },
3194 { id: 'horde_model', api: 'koboldhorde', type: null },3195 { id: 'horde_model', api: 'koboldhorde', type: null },
3195 ];3196 ];
public/scripts/tokenizers.js+9 -0
@@ -549,6 +549,15 @@ export function getTokenizerModel() {
549 return yiTokenizer;549 return yiTokenizer;
550 }550 }
551551
552 if (oai_settings.chat_completion_source === chat_completion_sources.BLOCKENTROPY) {
553 if (oai_settings.blockentropy_model.includes('llama3')) {
554 return llama3Tokenizer;
555 }
556 if (oai_settings.blockentropy_model.includes('miqu') || oai_settings.blockentropy_model.includes('mixtral')) {
557 return mistralTokenizer;
558 }
559 }
560
552 // Default to Turbo 3.5561 // Default to Turbo 3.5
553 return turboTokenizer;562 return turboTokenizer;
554}563}
src/constants.js+1 -0
@@ -195,6 +195,7 @@ const CHAT_COMPLETION_SOURCES = {
195 PERPLEXITY: 'perplexity',195 PERPLEXITY: 'perplexity',
196 GROQ: 'groq',196 GROQ: 'groq',
197 ZEROONEAI: '01ai',197 ZEROONEAI: '01ai',
198 BLOCKENTROPY: 'blockentropy',
198};199};
199200
200/**201/**
src/endpoints/backends/chat-completions.js+10 -0
@@ -18,6 +18,7 @@ const API_PERPLEXITY = 'https://api.perplexity.ai';
18const API_GROQ = 'https://api.groq.com/openai/v1';18const API_GROQ = 'https://api.groq.com/openai/v1';
19const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';19const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';
20const API_01AI = 'https://api.01.ai/v1';20const API_01AI = 'https://api.01.ai/v1';
21const API_BLOCKENTROPY = 'https://api.blockentropy.ai/v1';
2122
22/**23/**
23 * Applies a post-processing step to the generated messages.24 * Applies a post-processing step to the generated messages.
@@ -675,6 +676,10 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
675 api_url = API_01AI;676 api_url = API_01AI;
676 api_key_openai = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);677 api_key_openai = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
677 headers = {};678 headers = {};
679 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.BLOCKENTROPY) {
680 api_url = API_BLOCKENTROPY;
681 api_key_openai = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
682 headers = {};
678 } else {683 } else {
679 console.log('This chat completion source is not supported yet.');684 console.log('This chat completion source is not supported yet.');
680 return response_getstatus_openai.status(400).send({ error: true });685 return response_getstatus_openai.status(400).send({ error: true });
@@ -941,6 +946,11 @@ router.post('/generate', jsonParser, function (request, response) {
941 apiKey = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);946 apiKey = readSecret(request.user.directories, SECRET_KEYS.ZEROONEAI);
942 headers = {};947 headers = {};
943 bodyParams = {};948 bodyParams = {};
949 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.BLOCKENTROPY) {
950 apiUrl = API_BLOCKENTROPY;
951 apiKey = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
952 headers = {};
953 bodyParams = {};
944 } else {954 } else {
945 console.log('This chat completion source is not supported yet.');955 console.log('This chat completion source is not supported yet.');
946 return response.status(400).send({ error: true });956 return response.status(400).send({ error: true });
src/endpoints/secrets.js+1 -0
@@ -44,6 +44,7 @@ const SECRET_KEYS = {
44 ZEROONEAI: 'api_key_01ai',44 ZEROONEAI: 'api_key_01ai',
45 HUGGINGFACE: 'api_key_huggingface',45 HUGGINGFACE: 'api_key_huggingface',
46 STABILITY: 'api_key_stability',46 STABILITY: 'api_key_stability',
47 BLOCKENTROPY: 'api_key_blockentropy',
47};48};
4849
49// These are the keys that are safe to expose, even if allowKeysExposure is false50// These are the keys that are safe to expose, even if allowKeysExposure is false
src/endpoints/stable-diffusion.js+93 -0
@@ -8,6 +8,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
8const { jsonParser } = require('../express-common');8const { jsonParser } = require('../express-common');
9const { readSecret, SECRET_KEYS } = require('./secrets.js');9const { readSecret, SECRET_KEYS } = require('./secrets.js');
10const FormData = require('form-data');10const FormData = require('form-data');
11const { scheduler } = require('timers/promises');
1112
12/**13/**
13 * Sanitizes a string.14 * Sanitizes a string.
@@ -908,10 +909,102 @@ stability.post('/generate', jsonParser, async (request, response) => {
908 }909 }
909});910});
910911
912const blockentropy = express.Router();
913
914blockentropy.post('/models', jsonParser, async (request, response) => {
915 try {
916 const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
917
918 if (!key) {
919 console.log('Block Entropy key not found.');
920 return response.sendStatus(400);
921 }
922
923 const modelsResponse = await fetch('https://api.blockentropy.ai/sdapi/v1/schedulers', {
924 method: 'GET',
925 headers: {
926 'Authorization': `Bearer ${key}`,
927 },
928 });
929
930 if (!modelsResponse.ok) {
931 console.log('Block Entropy returned an error.');
932 return response.sendStatus(500);
933 }
934
935 const data = await modelsResponse.json();
936
937 if (!Array.isArray(data)) {
938 console.log('Block Entropy returned invalid data.');
939 return response.sendStatus(500);
940 }
941 const models = data.map(x => ({ value: x.name, text: x.name }));
942 return response.send(models);
943
944 } catch (error) {
945 console.log(error);
946 return response.sendStatus(500);
947 }
948});
949
950blockentropy.post('/generate', jsonParser, async (request, response) => {
951 try {
952 const key = readSecret(request.user.directories, SECRET_KEYS.BLOCKENTROPY);
953
954 if (!key) {
955 console.log('Block Entropy key not found.');
956 return response.sendStatus(400);
957 }
958
959 console.log('Block Entropy request:', request.body);
960
961 const result = await fetch('https://api.blockentropy.ai/sdapi/v1/txt2img', {
962 method: 'POST',
963 body: JSON.stringify({
964 request_type: 'image-model-inference',
965 prompt: request.body.prompt,
966 negative_prompt: request.body.negative_prompt,
967 height: request.body.height,
968 width: request.body.width,
969 model: request.body.model,
970 steps: request.body.steps,
971 scheduler: request.body.scheduler,
972 n: 1,
973 // Limited to 10000 on playground, works fine with more.
974 seed: request.body.seed >= 0 ? request.body.seed : Math.floor(Math.random() * 10_000_000),
975 }),
976 headers: {
977 'Content-Type': 'application/json',
978 'Authorization': `Bearer ${key}`,
979 },
980 });
981
982 if (!result.ok) {
983 console.log('Block Entropy returned an error.');
984 return response.sendStatus(500);
985 }
986
987 const data = await result.json();
988 console.log('Block Entropy response:', data);
989
990 //if (data.status !== 'finished') {
991 // console.log('Block Entropy job failed.');
992 // return response.sendStatus(500);
993 //}
994
995 return response.send(data);
996 } catch (error) {
997 console.log(error);
998 return response.sendStatus(500);
999 }
1000});
1001
1002
911router.use('/comfy', comfy);1003router.use('/comfy', comfy);
912router.use('/together', together);1004router.use('/together', together);
913router.use('/drawthings', drawthings);1005router.use('/drawthings', drawthings);
914router.use('/pollinations', pollinations);1006router.use('/pollinations', pollinations);
915router.use('/stability', stability);1007router.use('/stability', stability);
1008router.use('/blockentropy', blockentropy);
9161009
917module.exports = { router };1010module.exports = { router };