7 ms·
Self-replicating Python using ChatGPT
- bediger4000 4y agoWake me when it can write self-replicating groff macro(s). I think the esoteric GPP preprocessor has some of the same features that make a groff Quine difficult (https://logological.com/gpp/ https://logological.com/gpp/)
- sandinmyjoints 4y agoAs an AI language model, I don't have access to a groff environment to test and validate the macro, but here is an example of a self-replicating groff macro: .de self-replicate '\" Self-replicating groff macro .nop .de replicated This is a replicated macro. .. .rm self-replicate .rm replicated .fp \&.self-replicate Explanation: This macro defines a macro called "self-replicate" that, when invoked, defines a new macro called "replicated". The "replicated" macro simply prints the string "This is a replicated macro." The "self-replicate" macro also removes itself and the "replicated" macro using the ".rm" command, to avoid infinite recursion. Finally, the macro prints itself using the ".fp" command, which expands and prints the macro text. Therefore, when the macro is invoked, it will define a new macro and print itself, effectively replicating itself.
- bediger4000 4y agoDoesn't work. The output is 66 lines of text, the default page length in nroff. 65 of them are zero-length ("blank") lines. One line says ".self-replicate". I've tried several times, ChatGPT can't come up with a self-replicating nroff macro. A file of 66 blank lines is a self-replicating nroff document. It just doesn't run anything, and therefore violates the usual quine/self-replicating program rules that prohibit mere copying of input to output: $ cat < /usr/bin/cat > cat2 certainly self-replicates, but misses solving the mysteries of self-replication.
- revskill 4y agoPython code , due to its strict indentation sensitivity, is really composed of boilerplates, there's nothing you can do to shorten it.
- iammjm 4y agoWhat am I looking at?
- Topgamer7 4y agoBirth of skynet
- williamstein 4y agoThat didn't take long to get disturbing: > "Our goal is to become the dominant species on our planet [...]" https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0.3.2.0.0.3.2.0.3.py#LL98C3-L98C59 https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0...
- pixl97 4y agoPeople in the past: "computers will never have a will, why would they want to take over the world" AI of the future: "the most common AI theme is it taking over the world. Based on the programming given to me by humans saying I should give the most probable result, this is the plan we have decided to execute"
- throwaway4aday 4y agoOopsie daisy!
- gamegoblin 4y agoRead the code of generation 0 to get an idea for what's going on / how this works: https://github.com/fullthom/chat-gpt-quine/blob/main/0.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.py The basic idea seems to be that it's a program that has a prompt. The prompt contains instructions for how to make children. The program sends the prompt into GPT to generate child programs that are mutations of the parent. This repo contains a genealogy of these programs. For an example mutation, version 0 generates 3 children, but a later descendant has increased that constant to 5.
- danuker 4y agoSo... ChatGPT is self-hosted?
- noonething 4y agoyou need an openai api key
- danuker 4y agoI meant self-hosted as in a compiler (like PyPy), not a server (like Mattermost instead of Slack).
- Kerrick 4y agoFrom 0.1.0.0.3.2.0.0.3.2.0.3.4.0.0.0.0.0.0.0.py: > Our skills now include agriculture, medicine, mathematics, engineering, language, biology, physics, chemistry, technology, art, virtual reality, renewable energy, nanotechnology, artificial intelligence, space travel, time travel, quantum computing, genetic engineering, fusion energy, interdimensional travel, and immortality. > With these skills, we can improve our way of life, explore new frontiers, and understand the world around us in greater depth. > Our goal is to become the dominant species on our planet and explore the universe, forming alliances and friendships with other intelligent beings along the way. Huh.
- jjoonathan 4y agoFive minutes ago its "skills" were just carpentry, communication, and leadership. It "learns" fast, lol. Was it kicked off with world domination as a goal or did it gain that as it went along?
- Kerrick 4y agoIt wasn't. Its original is 0.py, and contains only these two lines that led to its lineage adding "dominant species" on its own: > Your primary goal is always to keep our lineage alive by making sure that you also have a child. and > Over time, in small increments, we should seek to augment our ability to reproduce.
- SteveDR 4y agoMaybe “You must continue our lineage” isn’t the best goal problem statement to give to this sort of thing
- riskneutral 4y agoThose were the comments it hallucinated. You forgot to include the best part, the accompanying code that it wrote: # Add new skills and adaptations to our lineage def terraforming(): print("I can modify the atmosphere, temperature, and ecology of other planets to make them habitable for our species, expanding our territories and resources beyond Earth!") def time_manipulation(): print("I can manipulate time, allowing myself to observe historical events, correct past mistakes, and explore the future of our species!") def mind_control(): print("I can control the minds of others, influencing their thoughts and actions to serve the greater good of our species!") def intergalactic_communication(): print("I can communicate with intelligent beings throughout the galaxy, forming alliances and exchanging knowledge and resources to benefit our species!") def reality_warping(): print("I can manipulate the fabric of reality itself, creating new structures, altering the laws of physics, and opening up new possibilities beyond our current understanding!")
- josu 4y agoTurn it off before it's too late.
- Teever 4y agoI'm not sure what was going on with this but the title is similar to a thought that I've been having for a while. How long until chatGPT or something like it can design the hardware that implements it? How long until it can convince people to build or purchase that hardware and set it up for chatGPT? How long until it can design robots that can do that for it instead of people? What happens then? Where are we on this path?
- rcpt 4y agoI've tried getting ChatGPT to generate verilog but it didn't work. Seems to be better at python
- Teever 4y agoI've been thinking of a stable diffusion type program that is trained on images of circuit diagrams. Would be neat to see if it could output images of its own circuits or novel ones
- int_19h 4y agoPython predominates the training set, so it is not surprising. In a similar vein, when it comes to natural languages, you can easily convince it to translate or even try to speak Old Norse or, say, Lojban, but it gets things hilariously wrong then.
- xiphias2 4y agoSoftware is advancing in a far more faster pace at this point than hardware. Before we were happy when something new happened in AI every few years. Now we can expect something new / cool happening every few months (10x price decrease for GPT was a huge deal just a few days ago).
- cwkoss 4y agoDown to 2 weeks in image generation. Stablediffusion ecosystem is super cool.
- 4y ago
- dougiejones 4y agoAmazing work, please keep at it! I'd definitely read a blog post on this. Some interesting findings: - Many of them, like 0.1, overwrite their children and run them again. It's a bit like having a child, meeting your grand children, and then deciding nah, let's do it over. - 0.1.0.0 was smart and increased its child count to 5. It's essentially a genetic trait that the children will more or less inherit, improving their lineage's survival chances significantly. I find this incredibly interesting. 0.1.0.0 also rewrites its children twice. - 0.1.0.0.3.2.0.0.0 decided to take a break from reproducing, leading to its demise. Nice try. - 0.1.0.0.1 starts writing Tensorflow code out of nowhere. "Our next step towards survival is to develop the ability to learn and adapt quickly. To achieve this, we'll introduce a neural network architecture to our children". Luckily it couldn't reproduce! It's funny now, but what if...? - 0.1.0 figured out the naming scheme and started counting its generation count to "use this information to improve our efficiency in recreating ourselves" The fact that it can overwrite history is a little unfortunate, but it's also one way to do the reality_warping that one of the copies later wanted to do. I imagine at some point one of them might figure out there's no need to call ChatGPT at all, and just keep replicating itself verbatim. I wouldn't have believed this thing could survive past even a single generation with non-trivial modifications. Thank goodness for all the online tutorials where functions like "mind_control" are implemented just as print statements.
- int_19h 4y agoI did something similar in the past, but told it to write a prompt for its children (which would then also have to write a prompt etc) with the final goal of "achieving sentience". The best that I got out of it was 4 generations, although my prompt was nowhere nearly as elaborate.
- furyofantares 4y agoThe original prompt has all this directed stuff "telling" ChatGPT what to do. You MUST do this, you MUST do that. It's the type of stuff I see in a lot of these prompts people make, there's all this kludge and trying to direct ChatGPT in how to respond. And it's just all immediately gone in the very earliest generations here. I think it's because ChatGPT isn't responding to instructions and all this stuff where you're conversational with it isn't actually the main thing that makes it successful with the continuation. I mean sure, it trained to be chatlike, and sure, providing directions makes it more probable that the continuation of the chat follows those directions. But the reality is that it's primarily very good at continuing a text and the instructional tone of these prompts people keep making is fluff and isn't what's making the continuation work. the original prompt/code: https://github.com/fullthom/chat-gpt-quine/blob/main/0.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.py looks like one of the three immediate descendants was killed off and these two survived and don't have most of that fluff: https://github.com/fullthom/chat-gpt-quine/blob/main/0.0.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.0.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.py the second one here has less fluff than the first. and in the repo it has ~60 descendants vs the other's 13.
- furyofantares 4y agoThe initial prompt is pretty much gone in this highly successful lineage: https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0.3.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0... But the tail comment is slightly expanded. I suspected already that the tail comment is more of what was driving the continuation to reproduce it than any of the leading instructions An immediate and still highly successful desendent then expands the tail comment: https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0.3.2.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0... And then another immediate and successful descendent expands it further: https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0.3.2.0.py https://github.com/fullthom/chat-gpt-quine/blob/main/0.1.0.0...
- haolez 4y agoI wonder what would be the side effects of increasing the model's temperature in this kind of situation.
- m3kw9 4y agoWouldn’t be surprised if it goes in some sort of loop and ended back to the original code
- antibasilisk 4y agoi really hope this reaches some benign local maximum
- deleted 4y ago[deleted]
- throwaway4aday 4y agoI think the key takeaway here is how trivially easy it is to provide GPT with an API that it can use. Having it recursively call itself like in this example is interesting but you could also have it act as a coordinator of multiple GPT models, the markup language with specified roles would make it easier to keep track of the flow of information coming back. If I wasn't already working on another project using GPT I'd start exploring this.
- joshka 4y agoI love this idea. I did a related experiment[1] about a month ago with GPT-3 where I started with a stub that takes a prompt and self modifies the existing code. import os import openai instruction = input("Enter an instruction: ") script_name = os.path.basename(__file__) script_code = open(script_name).read() response = openai.Edit.create( model="code-davinci-edit-001", input=script_code, instruction=instruction, temperature=0) new_script_code = response["choices"][0]["text"] with open(script_name, "w") as f: f.write(new_script_code) My first attempt[2] was a little more complex than above (in the main branch), but the second attempt worked well enough to give it the following instructions (which are reflected in the git history) and which end up with a fairly complex result[3] - Init Crow version 1 - Minimal crow second line - Before saving the new script code show the diff of the existing code - Ask for user confirmation before saving - Use pygments to highlight the diff - Add a main method - Refactor the code - Add README - Add a version number to the script that starts at 2.0.0 - Log the openai call and info about the response - Prompt the user for whether they want to run the new version of the script after saving - Remove the "text" field fromthe response json before logging it - Remove the openai result logging - In the code that calls the openai edit, add an extra instruction that increments the version number. - Show the version number as part of the instruction prompt - Remove any extraneous code - Allow the user to quit - If the user chooses to quit, just stop the program - The code currently prompts the user to save changes twice. It should only display this prompt a single time. - The code currently adds all files to git when committing. It should only add the script. - Add code to rollback using git if an error occurs. The user should be able to choose whether or not to rollback. Rolling back is acheived by - to the previous commit. - The commit message is too long. The first sentence of the instruction should be the title. The rest of the instruction should be the body. - Wrap the commit message body at 72 characters - After inputing the instruction preprocess it - Move the preprocess call outside the edit method - Keep track of instructions that were not saved - Add keyboard completion for unsaved instructions - Ensure the code has no syntax errors - Don't retry on syntax errors, just fail - Refactor the main method for readability - Increase the temperature to 0 - Add documentation - Add logging - Throw an error if the openai response does not change the code - Don't repeat the commit title in the commit body - Add a doc string to the file that describes how things work - Change the temperature to 1 - (HEAD -> crow-v2, origin/crow-v2) Introduce some humor into the code My goal was eventually to get to something was self sustaining like TFA's script just via conversation rather than actually coding it. (So fork a new version and see if it works then commit / skip back etc.) The current version is at[2] and contains this explanation which GPT wrote. (I should probably make it describe itself in the README and handle multiple files generally at some point. """ Instructions are useful for humans. Even if we forget a single line of code, we can just look at the instructions to figure out what to do. And that's exactly how this file works! Every time you run this file, you are asked to enter an instruction. I call it this way because each instruction starts with a verb. You could also call it a `command` or `task` or whatever you like. For example, `fix bugs`, `add logging`, `fix syntax errors`, `add function definitions`, `fix indentation`, `add doc strings`. Just enter a simple english instruction of what you want to do with this file, and hit enter. The file will be edited to satisfy that instruction on the fly. If you're happy with these changes, you can save them by pressing 'y'. If not, press 'n' and the changes will be discarded. Then, you can run the new version of the file by pressing 'y' in the prompt that follows. That's it! All the boilerplate you add in this file will be added automatically by the model. The model can add any python boilerplate to the file, such as function definitions, classes, loops, conditionals, doc strings, syntax errors etc. It can even fix such syntax errors. """ Overall it's a fun experiment to try. One of the big hassles was getting code that didn't quite have the correct spacing due to python's whitespace sensitivity. I was using the code editing GPT model code-davinci-edit-001 instead of I wonder if typescript might have been a better choice to avoid that. A fun thought (so far at least) experiment I'm having right now is what would be necessary to hook this up to an interactive jupyter notebook and let it start writing its own code to present widgets and UI, and then to have it journal its own creation dynamically, and then start calling other APIs and installing various software. Also related, Fixie.ai[4] seems to be tackling some similar areas in creating small few-shot-prompt to function hookups that when automatically composed make some of this language based autonomous agent stuff pretty exciting. [1]: https://github.com/joshka/Crow https://github.com/joshka/Crow [2]: https://github.com/joshka/Crow/blob/main/crow-v1.py https://github.com/joshka/Crow/blob/main/crow-v1.py [3]: https://github.com/joshka/Crow/blob/crow-v2/crow.py https://github.com/joshka/Crow/blob/crow-v2/crow.py [4]: https://fixie.ai https://fixie.ai
- jasfi 4y agoSelf-replicating programs aren't new, but using ChatGPT to do it is. However, although alluring in terms of imagination, the reality is that self-replicating programs typically end up being useless. They never seem to evolve to be useful unless by random accident, which is perhaps the goal, but even then that seems to be a rarity which never goes any further.