From 7bf7a134dbd2e61e98c73b78fb9f75ee572eae8d Mon Sep 17 00:00:00 2001 From: Banyanael <nbanyan@gmail.com> Date: Mon, 13 Nov 2023 19:40:07 -0500 Subject: [PATCH] Added Option setting for AI generation timeout * Added V.aiTimeoutPerStep to Game Options settings to allow the user to set the number of seconds their system is expected to take for each sampling step. * Added checks for variable minimums to the AI generation settings. --- js/003-data/gameVariableData.js | 3 ++- src/art/genAI/stableDiffusion.js | 2 +- src/endWeek/nextWeek/nextWeek.js | 2 +- src/gui/options/options.js | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index 6af7e14cbf9..9474af98943 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -174,8 +174,9 @@ App.Data.defaultGameStateVariables = { // Stable Diffusion settings aiApiUrl: "http://localhost:7860", aiAutoGen: true, - aiAutoGenFrequency: 0, + aiAutoGenFrequency: 10, aiCfgScale: 5, + aiTimeoutPerStep: 2.5, aiCustomImagePrompts: 0, aiCustomStyleNeg: "", aiCustomStylePos: "", diff --git a/src/art/genAI/stableDiffusion.js b/src/art/genAI/stableDiffusion.js index 8914af45d1c..aedeedc6be3 100644 --- a/src/art/genAI/stableDiffusion.js +++ b/src/art/genAI/stableDiffusion.js @@ -116,7 +116,7 @@ App.Art.GenAI.StableDiffusionClientQueue = class { }, body: top.body, }; - const response = fetchWithTimeout(`${V.aiApiUrl}/sdapi/v1/txt2img`, 3000 * V.aiSamplingSteps, options) + const response = fetchWithTimeout(`${V.aiApiUrl}/sdapi/v1/txt2img`, (V.aiTimeoutPerStep * 1000) * V.aiSamplingSteps, options) .then((value) => { value.json() .then (obj => { diff --git a/src/endWeek/nextWeek/nextWeek.js b/src/endWeek/nextWeek/nextWeek.js index c54f834fa54..d9f03f1f252 100644 --- a/src/endWeek/nextWeek/nextWeek.js +++ b/src/endWeek/nextWeek/nextWeek.js @@ -441,7 +441,7 @@ App.EndWeek.nextWeek = function() { V.NaNArray = findNaN(); // regenerate old slave images - if (V.aiAutoGenFrequency > 0){ + if (V.aiAutoGen && V.aiAutoGenFrequency > 0){ // executing this between DOM loads still picks up the "temporary-images" tag of the event passages, so we'll queue auto regeneration for a DOM to load without the tag. (We're not calling this from the "Main" passage to ensure it isn't over-called by reloading saves) (async () => { const sleep = () => new Promise(r => setTimeout(r, 100)); diff --git a/src/gui/options/options.js b/src/gui/options/options.js index 9f8ba56502b..d95f071e62e 100644 --- a/src/gui/options/options.js +++ b/src/gui/options/options.js @@ -1293,19 +1293,29 @@ App.UI.artOptions = function() { .addValue("Enabled", true).on().addValue("Disabled", false).off() .addComment("Generate images for new slaves on the fly. If disabled, you will need to manually click to generate each slave's image."); if (V.aiAutoGen) { + if (V.aiAutoGenFrequency < 1) V.aiAutoGenFrequency = 1; + V.aiAutoGenFrequency = Math.round(V.aiAutoGenFrequency); options.addOption("Regeneration Frequency", "aiAutoGenFrequency").showTextBox() - .addComment("How often (in weeks) regenerate slave images. Set to 0 to disable. Slaves will render when 'Weeks Owned' is divisible by this number."); + .addComment("How often (in weeks) regenerate slave images. Slaves will render when 'Weeks Owned' is divisible by this number."); } options.addOption("Sampling Method", "aiSamplingMethod").showTextBox() .addComment(`The sampling method used by AI. You can query ${V.aiApiUrl}/sdapi/v1/samplers to see the list of available samplers.`); + if (V.aiCfgScale < 1) V.aiCfgScale = 1; options.addOption("CFG Scale", "aiCfgScale").showTextBox() .addComment("The higher this number, the more the prompt influences the image. Generally between 5 to 12."); + if (V.aiTimeoutPerStep < 0.01) V.aiTimeoutPerStep = 0.01; + options.addOption("Seconds per Step", "aiTimeoutPerStep").showTextBox() + .addComment("The maximum number of Seconds (per Step) your system takes to render an image. This time is from the time the request is sent to the time it is saved divided by the number of Sampling Steps. Please set this at as small a value as reasonable to avoid the game from waiting longer than you are for images to generate."); + if (V.aiSamplingSteps < 2) V.aiSamplingSteps = 2; options.addOption("Sampling Steps", "aiSamplingSteps").showTextBox() .addComment("The number of steps used when generating the image. More steps might reduce artifacts but increases generation time. Generally between 20 to 50, but may be as high as 500 if you don't mind long queues in the background."); + if (V.aiSamplingSteps < 2) V.aiSamplingSteps = 2; options.addOption("Event Sampling Steps", "aiSamplingStepsEvent").showTextBox() - .addComment("The number of steps used when generating an image durring events. Generally between 20 to 50 to maintain a reasonable speed."); + .addComment("The number of steps used when generating an image during events. Generally between 20 to 50 to maintain a reasonable speed."); + if (V.aiHeight < 10) V.aiHeight = 10; options.addOption("Height", "aiHeight").showTextBox() .addComment("The height of the image."); + if (V.aiWidth < 10) V.aiWidth = 10; options.addOption("Width", "aiWidth").showTextBox() .addComment("The width of the image."); options.addOption("Restore Faces", "aiRestoreFaces") -- GitLab