promptOptions.context Send in a JS object or a list as a context the prompt has access to. Perhaps options to overload the window (falls through to the window if a name isn’t found within the context), or completely contained (only things within the context can be accessed: avoids any name clashing issues).

image({ plain_object }) Allow a normal JS object to be used. Currently the plugin relies on list properties here and there, which means it breaks when a simple JS object is sent even if it has the same exact used properties.

As JS is used to create these images in a lot of generators, this would cut out the need for the engine to get involved and generate the promptOptions object at all. And the creator doesn’t have to worry about how the lists work to be able to use the image generator.

promptOptions.select() When a button is clicked to “select” a particular generated image’s settings… if there’s a .select() function available, call it with everything to do with that generation: prompt object, etc. Maybe if there is no such function, don’t show that button.

This could be used to set up the generator’s textarea and other options in whatever way the creator sees fit. Or even to use this function for any other thing.

We can sort of half do this by giving each generation an id, and adding our own button next to it. And I think we can get some sort of info about a generation from its iframe? Maybe? Not sure.

But anyway, this would be a simple way of reaching in and out of the generation iframes.

Show prompt while loading: and just an idea to show the text prompt/negative prompt while the image is loading. It’s useful as a creator/user to see what the prompt is that’s actually generated–and nip it in the bud if we can see it’s malformed or bugged in some way. Just an idea.

  • @wthit56OP
    link
    English
    1
    edit-2
    3 months ago

    Oh, forgot to add an important one…

    Unprocessed: a completely unprocessed mode. So, zero changing or parsing or erroring on the prompt or negative prompt. So then the creator can process it in any way, or leave it “raw” to let users not have to worry about the perchance programming side, they can effectively just use StableDiffusion as-is.

  • @perchanceM
    link
    English
    13 months ago

    Currently the plugin relies on list properties here and there, which means it breaks when a simple JS object is sent even if it has the same exact used properties.

    Can you give an example? Works fine for me here: https://perchance.org/ai-character-description#edit so I’m guessing there’s a specific property you’ve found that doesn’t work.

    promptOptions.context

    You can write e.g. [c1={foo:1}, ""] and then later use [c1.foo] in your prompt - it of course creates a global (c1), but if that’s an issue, then you’re probably doing complex-enough stuff that you can do stuff inside a function, and have complete control. This pattern may also be useful:

    output
      [prompt.object=object.selectOne, prompt.animal=animal.selectOne, prompt]
    
    prompt
      the [this.object] belongs to the [this.animal]
    

    I think we can get some sort of info about a generation from its iframe?

    The iframe element itself has a textToImagePluginOutput property where you can access stuff like iframe.textToImagePluginOutput.inputs and iframe.textToImagePluginOutput.dataUrl. Not sure if this solves your issue - only skimming here, sorry!

    • @wthit56OP
      link
      English
      13 months ago

      I think it was when I was trying the referenceImage stuff. It errored seemingly on .evaluateItem, which I think is a list thing, so I thought that must be the issue. Though I just did a thorough test with all properties just in an object, and it all works. At least on the front of list vs object. (Does .evaluateItem just work on all objects, even non-list ones?)

      Here’s the test: https://perchance.org/ncehrh7jdu#edit. Note that there are a couple of silently failing ones for the image generation test.

      While testing though, I just found some very odd bugs concerning [code] in html. At least it errors when it doesn’t seem like it should. I’ll leave this here for you to look at while I remember: https://perchance.org/1jt36ldioy#edit.

    • @wthit56OP
      link
      English
      13 months ago

      Ah sorry, I wasn’t clear regarding the context idea. This is from the standpoint of a creator adding common features like making evaluatable names/vars, like ai-text-to-image-generator does with the scratchpad. Seems like we need to set window[name] = string for any of them we want to be referencable in the prompt. And also that the prompt can reference any list, for example we can prompt with [settings.imageOptions=""] which breaks the page.

      If it could run against its own separate context, with no access to the page’s list and such, it would be safer for the creator. And being able to just stick those names into an object, and then send the object in would be simpler too.

      • @wthit56OP
        link
        English
        12 months ago

        @[email protected] Started making my own image-gen page now. And got context working using this code:

        var root = createPerchanceTree(code_input.value + `
        prompt=${prompt_input.value.replaceAll("\n", " ")}
        negativePrompt=${negativePrompt.value.replaceAll("\n", " ")}
        `);
        
        var settings = {
              prompt: root.prompt.evaluateItem,
              negativePrompt: root.negativePrompt.evaluateItem
        ...
        };
        

        See what I mean? This way, the prompt is evaluated against just whatever code the user has set up for it to use, and has no access to the page’s root or code at all. It’s safer because of that, is what I was talking about. (Apart from [window.root] or something I guess?)

        Also, they just have full perchance capabilities, and can use any names they wish to.

        • @perchanceM
          link
          English
          1
          edit-2
          2 months ago

          Ah I see what you mean. Sounds like you basically want an “isolated” version of createPerchanceTree? The way I do something similar on perchance.org/ai-character-chat (where bots can have customCode which could be malicious for shared characters, and so needs to be sandboxed) is to create an iframe. Open that page and ctrl+f for evaluatePerchanceTextInSandbox in the list editor. I think you should actually be able to just copy-paste that function and it’ll work - I definitely won’t make backwards-incompatible changes to /ai-character-chat-sandboxed-executor, since forks of /ai-character-chat are relying on it. But you may need to make some changes depending on the specific thing(s) you’re trying to achieve.

          But if I understand your request correctly, the “real” solution to this will probably require waiting for the ShadowRealm proposal to become available in all major browsers, since otherwise it has to be an async call, which is annoying. ShadowRealm is finally making solid progress lately, so I’m hopeful that we’ll get it in Chrome/Edge within a year or so. Firefox and Safari may take longer though. I think it may be possible to use something like this: https://github.com/endojs/endo/blob/master/packages/ses/README.md but I’m not sure - seems fragile to new browser features and stuff, so would probably need to be kept up to date to maintain the security boundary (maybe not - I’m not entirely sure how it works).

          • @wthit56OP
            link
            English
            1
            edit-2
            2 months ago

            Yes, exactly. I’ve actually been able to do this with just createPerchanceTree. They can probably mess with the window–that’s up to them. But at least they cannot access the main generator’s properties and such. And this also means you can give people full perchance coding abilities, without the requirement of only all-caps property names and polluting the window namespace and such.

            I’ve integrated it into my advanced text to image plugin :)

            • @perchanceM
              link
              English
              12 months ago

              Oh, nice! I might steal some of these ideas eventually ^^’