Hi list,
Stefan Reich showed me something in a chat yesterday that I found
quite nifty, and I think that it deserves a quick announcement here on
lua-l... the most evident part of it is a sandboxed Lua environment
with persistence and with a web interface - a quick hack done with
LuaJ and Java, according to him, with a bit of PHP for the web stuff -
but all that is built on top of an AI engine that he is creating,
which - this is what I felt was more interesting - stores both learned
things and test cases as Lua code.
Here are some links:
DISCLAIMER: I have a feeling that there may be several nice code
snippets (and ideas, ways of prototyping things, etc) behind all that,
but that's just an impression - I didn't have time yet to inspect the
source...
To make this somewhat self-contained - at the expense of a few more
bytes - let me quote from two of the links above.
Cheers,
Eduardo Ochs
--snip--snip--
Chat-bots in Lua
================
TinyBrain (TinyBrain.de) now offers a way of creating a chat-bot (a
program you can talk to) using very simple Lua code.
Software installation required on your machine: none. All you need is
a browser. Your chat-bots will be available on the Internet instantly.
To create a chat-bot, upload a snippet of Lua code to the TinyBrain
code - Chat-bot" and make the snippet public by ticking the
appropriate checkbox.
Remember the snippet's ID, e.g. #123 and enter the ID on the front
That's all!
How to write the code
=====================
You'll get the user's last input in the variable "input". So a simple,
stateless bot can look like this:
return(input == "" and "Say something!" or "You just said: "..input)
Yes, that's only one line of code. :)
Stateful bots
=============
Of course it is nice to have the bot remember something between user
lines. To do this, use the "cookies" table, which is a Lua map (with
string keys and string values).
end
return("Hello "..cookies.name.."!")
else
return "What's your name?"
end
Yes, that's all. btw, the cookies are totally persistent - even
between server restarts.
--snip--
Hello! I'm TinyBrain. Please choose a personality for me, for example "#27".
#31
Personality #31 loaded & ready to serve. Please enter a transformation example, e.g. abc=ABC
small=SMALL
Solution found: return input:upper()
BIG=big
Solution found: return input:lower()
Ha - works!
Please enter a transformation example, e.g. abc=ABC