-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python object macro support #9
Comments
Wow. This is old but I overcame this issue five years ago -- sorry I didn't see this until now. My rivescript looks like this:
When the chatbot sees the first word of the response is a LocalCommand (You can change the name of this keyword in the settings file). It knows to exec everything after this. THis can be easily executed a better way than I did originally by using github.com/bitfield script:
This allows my chatbot users to create commands in ANY language they prefer, or use standard Linux commands. I also have a version of this for 'RemoteCommand' that executes them on other servers using SSH. |
@rmasci I've done similar before, like this example to run Perl object macros for the Python version of RiveScript: https://github.com/aichaos/rivescript-python/tree/master/eg/perl-objects The various RiveScript versions have a SetHandler() function to register custom programming language hooks for non-native languages (up to the programmer to implement how those hooks work). The Python module also has a JavaScript example for bots that run out of a web browser environment (so the JS macros are run using embedded Being that Go sits at a close level to C and can embed CPython (or Perl or other C-based languages) it may be possible to get a wide variety of languages "natively" supported without shell commands calling out to third party scripts to bridge the gap. Though on that latter idea, I was once playing with the idea of defining a 'standard' interface for all RiveScript libraries to be able to interact with any third party language (e.g., by a standard format for input/output similar to the CGI standard for web scripts) -- with the idea that hacks like that perl-objects example didn't need to be done in an ad-hoc basis by individual developers but that somebody could take a Perl wrapper (e.g.) and use it on any of the 5 RiveScript libraries with built-in support for the protocol. In more recent years I have some further ideas that could be used:
|
It'd be nice if rivescript-go were able to parse and run Python object macros for RiveScript bots, by using the Python C API.
There are two projects I found so far: sbinet/go-python and qur/gopy. They both only support Python 2 so far, but that will work for now.
I did some experimenting and came up with the following Go code that demonstrates the key pieces of functionality needed: dynamically parse a Python function, call the function giving it an array of string arguments, and retrieve the result of the function as a Go string.
This code lets us:
*args
tuple, converting Go strings into Python strings for theargs
argument (which is alist(str)
type)The other huge TODO is the
rs
parameter to the Python function: the above code sends in aNoneType
, but IRL it would need to provide an object with at least a subset of the RiveScript API (most importantly, functions likers.current_user()
andrs.set_uservar()
& friends). I imagine to expose the full RiveScript API to Python I'd need to write a whole wrapper class that translates all the arguments to/from Python types, but I'll probably just focus on the aforementioned useful functions to start out with.The text was updated successfully, but these errors were encountered: