![](/static/253f0d9b/assets/icons/icon-96x96.png)
![](https://lemmy.world/pictrs/image/fe882c27-7ec3-429e-a086-03d5a3efb517.png)
Thanks! Fixed.
Thanks! Fixed.
Today I learned - thanks! I was thinking about how annoying all the internal/plugin logs were recently, but didn’t know about console.debug
(I was going to fix via a localStorage
flag). Let me know if there are any stray logs that I’ve missed in the engine, or commonly used plugins.
I’ve kept ai-text-plugin input logging for each generation request, since I use that all the time (to make sure I’ve not made any mistakes constructing my prompt), so I assume others will find it useful too.
It’s always funny when I get a perchance error in the red box that’s some obscure problem internally
Can you give an example generator with an engine-internal error? Sounds like you’ve found a bug.
Thank you! Fixed.
This is correct/expected behavior, and isn’t Perchance-specific, but I’ll admit it’s confusing. It’s basically “JavaScript labelled statements strike again”. This is valid JavaScript:
{
let a = 10;
x:2
}
The curly braces define a block, so that the a
variable is only defined within that block - this is very handy, and I use it quite a lot. It’s equivalent to:
if(true) {
let a = 10;
x:2
}
The x:2
on the other hand is unusual and wouldn’t be written in “normal” code. It’s a labelled statement, but it’s a useless one, since there’s no way to actually “use” it.
So TL;DR: {x:2}
is being treated as a block with a labelled statement rather than a JavaScript object. The workaround is to wrap it in parentheses like [ ({ x:1 }) ]
instead of [ { x:1 } ]
.
I’ve added some comments to your example generator:
b = [ {} ] // a block with nothing in it
d = [ { x:1 } ] // a block with a labelled statement, x:1
e = [ x = {} ] // assignment, and so right hand side is constrained to be an expression - i.e. cannot be a block
f = [ { toString: function f() { return "hey"; } } ] // same as d
g = [ x2 = { toString: function f() { return "hey"; } } ] // same as e
You can test all of the above using eval like: eval("{x:1}")
to see it’s not Perchance-specific. To add to the confusion, DevTools does some “magic” on top of eval
in order to basically prioritize interpretation as an object, I think.
I like DevTools’ approach better, and have actually considered “fixing” this, since it would be weird to use JS blocks with labelled statements inside square blocks, but it’s probably too late due to backwards-compat issues, and would need to wait for V2 of the engine.
Even though it’s not technically a bug, I’ll link this comment from perchance.org/known-bugs as something to improve on in V2 of the engine.
Same issue for console.log(). And debugger.
Hmm, okay, thanks for bearing with me on this - can you try again now? I think I may have fixed it. If not, can you try logging document.readyState == 'complete'
above your addEventListener
call and tell me what it says?
Thanks! Fixed.
Hmm. If it’s during page load, then I think I should encourage people to use $meta.title
for that, since that’s what search engines will see. I.e. it might be misleading if, during page load, document.title
takes precedence, but then later they see that search engine’s aren’t using that. (Note that some search engines will run the full JS/iframe for certain popular pages, so they would see document.title
, but it’s not guaranteed)
:target
What’s this?
not being able to see the path it’s received is a bit annoying
Fixed, thanks!
Should I scour the windows object for such hidden gems
Nope, just https://perchance.org/advanced-tutorial - and if you find something that you want to use, but isn’t documented there, please let me know
Yep, if you have <div id="abc">[animal]</div>
and you have <button onclick="update(abc)">randomize</button>
then it’ll only update that particular HTML element with id="abc"
. Examples:
BTW, there are quite a few examples on perchance.org/examples and Google has indexed them - e.g. I found these quickly by searching “multiple buttons perchance example” and “perchance history example”. It can sometimes be hard to phrase Google searches when you’re new to a subject, so should feel very welcome to ask questions like this here - just a heads up in case it’s helpful next time you run into an issue like this.
As a general strategy for parsing stuff out of free-form/natural language, I’d definitely recommend using the AI text generation rather than regex, since natural language is so diverse that regex will fail a lot of the time. In most cases there are too many different ways that things can be said to be able to capture them all with regex.
I assume you’re talking about perchance.org/ai-character-chat custom code, and if so, you could do something like this:
function scanDescription(description) {
let result = await oc.getInstructCompletion({ // oc.getInstructCompletion is the /ai-character-chat custom code equivalent to perchance's ai text plugin
instruction: `Convert the following description into a JSON object like this: { lastName, race, politicalEntity, rank, position }\nDESCRIPTION: ${description}\n\nRespond with just the one-line JSON object, and nothing more.`,
startWith: `{ "lastName":`, // make it start off with the correct format (to ensure it doesn't e.g. say "sure! I can help you with that...")
stopSequences: ["}"], // force it to stop at the end of the JSON, just in case it doesn't stop by itself (e.g. tries to say "there you go!" or something)
});
return JSON.parse(result.text);
}
// Example usage:
let info = "Nick, a 49-year-old man, is from a small farming town in Iowa. His last name is Young, he is human, and he holds the rank of Captain in the local police force. His political entity is the United States.";
let result = await scanDescription(info);
console.log(result.politicalEntity);
console.log(result.lastName);
// ...
More info on custom code for perchance.org/ai-character-chat is here: https://rentry.org/82hwif
10 acres i just bought
Congrats!
Hmm, I’m not sure what’s going on there. Can’t seem to replicate. Which OS? I tested on Ubuntu, Windows, and an old Chromebook.
Can you try swapping it for a console.log instead of alert? I figure there’s a small chance that it’s a ‘user agent intervention’ where it hides the alert due to it seeming like a spammy thing.
(Note that Perchance is actually a platform for creating generators/applications, and it sounds like you’re talking about one particular generator, made by one particular user - namely perchance.org/ai-character-chat - in this case I happen to be that ‘user’. This is just a heads up because a lot of people who land here think that perchance is an AI chat site or whatever. It’s actually a platform where anyone can create random generators, and other things like AI chat applications)
it just… Goes “stupid”?
when I make more advanced AIs it tells me they can’t access websites or show me the contents.
it’ll run through the Lore Querying then it doesn’t provide its “Generated Response” in regards to the facts in the Lores.
I can probably fix all of these things, but I need example threads where they happened. If any of them happen again and if you’re able to share (in reply here, or via DM) a snapshot of a thread using this save button:
then I should be able to work out what’s happening and fix it. Without example threads, it’s really hard for me to fix stuff like this. But the moment someone gives me an example thread/export, or an easy way to consistently reproduce the issue, I can usually fix/improve it really fast.
This Generator Has Errors
Are you able to explain the steps I can take to reproduce this error? I just created a character, and added some example lore, and saved it, and it seems to work fine, so it might be related to some settings in your character, or something like that. If you’re not able to reliably reproduce it (i.e. it happens randomly), then another helpful thing would be to click that “this generator has errors” notice and copy/screenshot the error message that is shown.
Seems to be working fine for me in both cases - i.e. I see “loaded” alert when I load the page with and without #edit
at the end of the URL. Can you give more details? I’ve tested in Chrome and Firefox.
Thanks!
I’ve hackily fixed <a href="#foo">foo</a>
clicks so they work properly now.
I’ve also added a fix so if you visit perchance.org/whatever#foo it’ll correctly try to scroll to the id="foo"
element if it exists: https://perchance.org/dkp9npcidc#foo - pinging @VioneT@lemmy.world
You can also type a hash into the address bar of an already loaded page and press enter, and it’ll scroll to the element, like a normal top-level page does.
I’ve also fixed history.replaceState
so you can now change the query string of the top-level frame as shown below. It’ll throw an error if you try to change the pathname, since that could allow for malicious ‘spoofing’ of other generators as mentioned above.
history.replaceState({}, "", `/${generatorName}?foo=1`)
window.location.hash = "#foo"
(you can also do this with replaceState
IIUC).document.title = "foo";
and it’ll propagate to the top-level frame.<link rel="icon" href="https://exampe.com/image.png">
to <head>
) and it’ll propagate to the top-level frame.Let me know if you find any bugs 👍
And I’ve added a hideGalleryButtons
to the text to image plugin.
Allowing general-purpose cross-domain access like this is not possible, since it would allow very easy login credential stealing, and stuff like that, but these particular things that you’ve mentioned are good suggestions.
RE gallery button: You’re talking about the “send to gallery” and the “open gallery” buttons in the menu after clicking the heart button, right? Would something like this work?
promptData
prompt = ...
hideGalleryButtons = true
I have needed history.replaceState
before myself, but haven’t gotten around to properly thinking about it. I think it should be fine to allow a generator to change the query parameters and hash (i.e. everything other than the pathname - since otherwise could ‘spoof’ other generators/pages). Can you let me know your specific use case to help me triangulate on a good approach here? Do you specifically need pushState? Or will replaceState do? I’m reluctant to add pushState because it can be used ~maliciously - like the spammy sites that effectively hijack your back button to prevent you from leaving the page (or at least, make it require an extra click or two).
Oh, right, yes, when using evaluateText
on said string, that makes sense - due to square blocks having the policy of always “saving escape-char-processing until right at the end” as mentioned above. And yeah I agree this inconsistency is very annoying!
I think it may have been swept up when I was trying to stop comment plugin spam. I was dealing with a DDoS at one point but IIRC that was not Tor-related. I’ve made an edit to the firewall rules now so Tor blocking should be targeted to just comment plugin message-sending requests. Thanks!