Hello all,
So I'm inviting grandma to stay with the family for a while, but the catch is - she's invited to *your* computer. I decided to blow some dust from the most ancient Eliza chat bot code I could find, and then adapt it for 2021's QB64. Of course, this means you won't be speaking to her in a terminal-like interface: you will use your browser for this one. Allow me to 'splain:
The main feature here is a "small", kindof "general" HTML server for qb64. This can run for the web, but the entire intent is that this runs locally on your network (or the whole Internet if you have port forwarding). This kind of stuff is used behind the scenes in certain projects and then forgotten about, and it raises no questions among our folks - so I think it's a good idea to get more people on board with coding web-based things.
So this is a server. You run it, a window opens, and it just... serves. It waits for requests. Requests from where? Your browser. When the program is open, navigate to
http://127.0.0.1:10314 (so just come back, click that link once you run the exe), and you will see a webpage like this:
If you type into the input bar and press enter, the server decides what to do with that you typed, like this:
That is, normal text is just echoed back to you. But if you start a line with one single quote, and then a space, like
' hello
... then Eliza will kick in, and administer therapy to you.
This can do something more advanced, too. Consider the existence of a very simple, or maybe somewhat complex program called
external.exe. The simplest functioning example of this would be these four lines:
All it does is take and argument and write it to a file, pretty much. But of course this could be a more complicated process to do more work on its input. Point is: You can send input to external.exe through the browser too, bypassing Eliza. Using the syntax
#=whatever
, your response received back will be "Received: #=whatever".
This is meant to be one of the simplest nontrivial uses of a QB64 Html server. Certain parts might seem overengineered, some under - while these things may both be true, what I can attest is that this codebase served many purposes for a long time running, so it should work pretty well for what we're asking of it.
You will need four files to compile:
Qliza64.bas
eliza.bi
eliza.bm
index.html
Make sure the compiled exe is in the same folder as everything else. Either create a new folder for these or dump them into your qb64 folder. Oh and for the lazy, here is what the transformed Eliza code now looks like, haha: