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:
		| @@ -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]; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user