Oliver asks:
Hello,
I'm looking for a way to solve the following scenario using Rivescript and Python. The chatbot has no answer to a question, in this case it asks the user for the correct answer and records it in the rivescript file.
Do you have an idea? Does it even work in Rivescript?
Thanks
Best wishes Oliver
Hey Oliver
This can be done with a little bit of creativity. Self-learning bots aren't an officially supported feature in RiveScript, but you can get something to work using object macros that write new replies out to .rive
files to grow the bot's brain over time.
There's an example for this in the JavaScript edition of RiveScript, but its logic could be ported over to Python easily enough: https://github.com/aichaos/rivescript-js/tree/master/eg/learning
RiveScript Playground example you can test in your web browser: https://play.rivescript.com/s/0r4ZYvklR9
The basic ideas are:
+ when i say * you say *
allows the user to teach the bot a new reply.
rs.set_uservar(username, "origMessage", message)
when i say * you say *
trigger re-parses the user's message to get the original punctuation and formatting they used.learned.rive
file and also calls stream()
to load the new reply for immediate use by the bot "right now."The JavaScript example linked above works whether or not the program set the origMessage
variable: if the program did not set the variable, the learned reply is just somewhat limited to only include simple text with very few punctuation symbols preserved.
There are 3 comments on this page. Add yours.
Thank you
when using the macro online and on a chromebook where are those learned responses stored? I used the example and can't seem to find the responses to save them for future use. How can I access those responses?
The web demo version stores the learned responses in your web browser's localStorage, you can see them by opening your browser's developer console (F12 key, usually) and typing "localStorage" in the JS console, example:
> localStorage
Storage { "learned.rive": "! version = 2.0\n! local concat = none\n\n+ hello\n- World\n", length: 1 }
The web demo only stores them locally with your web browser, of course. A real deployment (which learns from multiple users) would need to store the learned file somewhere persistently (server-side filesystem, in a database, etc.)
0.0109s
.