I’ve added a new command to my telegram bot: js
. This command will ask GPT3 to generate javascript code and then run it.
For instance if I say ask it to generate a function to reverse a string, it will create function that reverses the letters one at a time.
As GPT3 tended to respond with code that defined functions, I realized I could build up a library of functions! And by sending the list of functions as context for further runs, further functions could be based on existing functions.
As a lark, I decided to include the gpt
function I wrote to access GPT3 in the library of functions - allows the bot to write code that calls out to another AI instance at runtime.
At first it was working great, asking it to build up small functions and then it would use them to build larger functions using the existing functions (sometimes .. sometimes not)
Asked by a friend to code a javascript graphics SDK, rather than coding it, it decides to flesh out the goals and call out to another AI instance to do the actual work… 😂
AIs are lazy coders too!
Technical implementation
My telegram bot is written in nodejs, allow easy use of unsafe eval
to run code returned by GPT3.
If the code is eval’d, it will be run in the same context as the bot, with access the bot’s local variables and functions. (not a good idea, this was a quick experiment!)
By saving any code returned with a short description, it can be added to the context:
reverseString(str) // reverse a string
gpt(prompt) // call GPT3 with a prompt
js(prompt) // ask GPT3 to generate code with library of functions
Then I can call GPT3 for completion to generate code with the library context and multi-shot prompt.