MCPcopy Create free account
hub / github.com/easydiffusion/easydiffusion / constructor

Method constructor

ui/media/js/engine.js:804–848  ·  view source on GitHub ↗
(options = {})

Source from the content-addressed store, hash-verified

802
803 class RenderTask extends Task {
804 constructor(options = {}) {
805 super(options)
806 if (typeof this._reqBody.seed === "undefined") {
807 this._reqBody.seed = Math.floor(Math.random() * (MAX_SEED_VALUE + 1))
808 }
809 if (
810 typeof typeof this._reqBody.seed === "number" &&
811 (this._reqBody.seed > MAX_SEED_VALUE || this._reqBody.seed < 0)
812 ) {
813 throw new Error(`seed must be in range 0 to ${MAX_SEED_VALUE}.`)
814 }
815
816 if ("use_cpu" in this._reqBody) {
817 if (this._reqBody.use_cpu) {
818 this._reqBody.device = "cpu"
819 }
820 delete this._reqBody.use_cpu
821 }
822 if (this._reqBody.init_image) {
823 if (typeof this._reqBody.prompt_strength === "undefined") {
824 this._reqBody.prompt_strength = 0.8
825 } else if (typeof this._reqBody.prompt_strength !== "number") {
826 throw new Error(
827 `prompt_strength need to be of type number but ${typeof this._reqBody
828 .prompt_strength} was found.`
829 )
830 }
831 }
832 if ("modifiers" in this._reqBody) {
833 if (Array.isArray(this._reqBody.modifiers) && this._reqBody.modifiers.length > 0) {
834 this._reqBody.modifiers = this._reqBody.modifiers.filter((val) => val.trim())
835 if (this._reqBody.modifiers.length > 0) {
836 this._reqBody.prompt = `${this._reqBody.prompt}, ${this._reqBody.modifiers.join(", ")}`
837 }
838 }
839 if (typeof this._reqBody.modifiers === "string" && this._reqBody.modifiers.length > 0) {
840 this._reqBody.modifiers = this._reqBody.modifiers.trim()
841 if (this._reqBody.modifiers.length > 0) {
842 this._reqBody.prompt = `${this._reqBody.prompt}, ${this._reqBody.modifiers}`
843 }
844 }
845 delete this._reqBody.modifiers
846 }
847 this.checkReqBody()
848 }
849
850 checkReqBody() {
851 for (const key in TASK_DEFAULTS) {

Callers

nothing calls this directly

Calls 1

checkReqBodyMethod · 0.95

Tested by

no test coverage detected