Author Topic: Everyone meet Qliza64  (Read 3378 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Everyone meet Qliza64
« on: January 21, 2021, 06:07:05 pm »
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:

screenshot.png


If you type into the input bar and press enter, the server decides what to do with that you typed, like this:

pic.png


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
Code: [Select]
' 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:
Code: QB64: [Select]
  1. PRINT #1, "Received: " + COMMAND$(1)

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
Code: [Select]
#=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:

elizacode.png
* Qliza64.bas (Filesize: 21.72 KB, Downloads: 146)
* eliza.bi (Filesize: 6.89 KB, Downloads: 142)
* eliza.bm (Filesize: 3.17 KB, Downloads: 149)
* index.html (Filesize: 1.53 KB, Downloads: 156)
« Last Edit: January 22, 2021, 12:10:28 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Everyone meet Qliza64
« Reply #1 on: January 21, 2021, 07:35:52 pm »
Does this chat bot learn from what you say or does it say the same thing all the time to everyone?

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Everyone meet Qliza64
« Reply #2 on: January 21, 2021, 07:53:28 pm »
Eliza "uses" what you say, but that's as deep as she goes. No context, no memory, like a goldfish, like grandma.
You're not done when it works, you're done when it's right.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Everyone meet Qliza64
« Reply #3 on: January 21, 2021, 11:47:33 pm »
That's cool, I like how you adapted it, good job!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Everyone meet Qliza64
« Reply #4 on: January 22, 2021, 04:18:35 am »
I made a Joe Biden version, but it only says, "Pudding!"

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/