this post was submitted on 19 Jul 2024
1 points (66.7% liked)

Perchance - Create a Random Text Generator

448 readers
17 users here now

⚄︎ Perchance

This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.

Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)

This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.

See this post for the Complete Guide to Posting Here on the Community!

Rules

1. Please follow the Lemmy.World instance rules.

2. Be kind and friendly.

  • Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)

3. Be thankful to those who try to help you.

  • If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)

4. Only post about stuff related to perchance.

  • Please only post about perchance related stuff like generators on it, bugs, and the site.

5. Refrain from requesting Prompts for the AI Tools.

  • We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (text-to-image-plugin and ai-text-plugin) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?"
  • See Perchance AI FAQ for FAQ about the AI tools.
  • You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
  • We will still be helping/answering questions about the plugins as long as it is related to building generators with them.

6. Search through the Community Before Posting.

  • Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.

founded 1 year ago
MODERATORS
 

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.

top 8 comments
sorted by: hot top controversial new old
[–] wthit56 1 points 3 months ago* (last edited 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.

[–] perchance 1 points 3 months ago (2 children)

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!

[–] wthit56 1 points 3 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.

[–] wthit56 1 points 3 months ago (1 children)

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.

[–] wthit56 1 points 3 months ago (1 children)

@[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.

[–] perchance 1 points 3 months ago* (last edited 3 months ago) (1 children)

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).

[–] wthit56 1 points 3 months ago* (last edited 3 months ago) (1 children)

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 :)

[–] perchance 1 points 3 months ago

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