• BluePower
    link
    fedilink
    English
    arrow-up
    4
    ·
    4 months ago

    You can check out the Perchance FAQ which talks about a question about open source Perchance and more, but here’s an explanation:

    Will there be an open-source Perchance library for programmers? Ideally, yes. The only reason there isn’t one already is because Perchance was built in a very “MVP” manner. (Talking to the programmers here,) I’ve altered the prototypes of inbuilt objects (Array, String, etc.), inadvisably hacked together Proxys and with statements to construct fake scopes and execution chains, simulated operator overloading by playing with valueOf and well-known Symbols, used eval unreservedly, and, in general, summoned every other JavaScript demon needed in order to get the Perchance DSL’s syntax to work nicely (all code inside square brackets is executed as plain JavaScript, for those who missed that). So currently Perchance isn’t in a state where it’s easy to pull out the engine, throw it into an NPM module and call it a day (until this proposal becomes a reality, that is). If you’re okay with the aforementioned mess, then you can pretty much just grab the .js files that are used in the iframe, include them in your project and use them the same way they’re used in the iframe html (you just pass createPerchanceTree your a string of perchance code and it returns the “root” of the tree, which you can then use to call the sublists).

    — Perchance FAQ

    • perchance@lemmy.worldM
      link
      fedilink
      English
      arrow-up
      3
      ·
      4 months ago

      Yep - core engine code is completely open source, though the code is extremely messy as mentioned in the above quote. Also mentioned above, the ShadowRealms will solve that (by isolating the messiness so it doesn’t affect the rest of your codebase), and that spec is finally making significant progress lately. A few random notes:

      • Probably the most annoying thing that’s not open source at the moment is the AI plugin stuff. It wouldn’t be hard to edit the AI plugin code to just use an external API service, but this is unfortunately not feasible for a lot of people because AI stuff is expensive. There are various workarounds, including setting up local models (e.g. using ollama + ComfyUI/A1111 + etc), and maybe eventually even local models within the browser (see Transformers.js) but for now this is just not very easy, and you need a powerful GPU. Still, I’d like to see someone in the community try to play around with these ideas. Note that Perchance exclusively uses open-source models for the AI stuff, so you can replicate all the capabilities by just using top models from civit/localllama/etc.

      • The express.js and mongodb server would be very simple for someone to make. It’d be very hard for me to open source the actual server (and also the AI plugin servers), since it would expose various defence-in-depth abuse-prevention methods, and I’d need to disentangle it from various things like my Cloudflare account (workers, caching rules, etc.), Deno Deploy, B2 Backblaze, and a bunch of other stuff. There are a lot of moving parts that wouldn’t be needed for self-hosting, which is why it’d be way easier for someone from the community just built it from scratch. It wouldn’t need to be much more than a “hello world” example of express.js and mongodb - basically connect it to this the bare-bones “offline editor”: https://www.reddit.com/r/perchance/comments/yi0twl/dev_you_can_now_edit_your_downloaded_generators/ - see also: https://perchance.org/better-offline-editor

      • This may be useful depending on your use case: https://perchance.org/diy-perchance-api

      • There have been a few projects which try to replicate a subset of the Perchance engine in other languages - https://pypi.org/project/PyChance - https://crates.io/crates/purrchance - there may be others.

      • BluePower
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 months ago

        That is a very neat explanation! Would be very useful for someone who wants to deep dive into the deepest sides of Perchance. And actually, I’d be interested in learning more on that, too.