I got ChatGPT to replicate itself

CyberPunkMetalHead
6 min readDec 8, 2022

ChatGPT is a powerful AI-powered chatbot created by OpenAI that is pretty damn impressive in what it can do. It can write poetry, create stories, come up with creative ideas for marketing campaigns, and as it turns out, it’s surprisingly good at coding. In fact, ChatGPT is so good at coding, that it was able to completely replicate itself. Here’s how the conversation went:

Me: Hi

CGPT: Hello! How can I help you today? Let me know if you have any questions, and I’ll do my best to provide answers.

Me: I want you to build an AI chatbot that using python and flask that takes a user message and displays the bot’s response on a frontend.

CGPT:

from flask import Flask, request, jsonify

import openai
openai.api_key = "YOUR_API_KEY"

@app.route('/chatbot', methods=['POST'])
def chatbot():
user_message = request.get_json()['message']
response = chatbot_response(user_message)
return jsonify({'response': response})


def chatbot_response(user_message):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=user_message,
max_tokens=1024,
n = 1,
temperature=0.5
)
return response['choices'][0]['text']

if __name__ == '__main__':
app.run()

To integrate the chatbot with a frontend, you can use the Flask app to serve a HTML page that includes a form for entering a user message and displaying the chatbot’s response. The form can be submitted using an AJAX request to the /chatbot route, and the chatbot's response can be displayed on the page using JavaScript.

Some bits of code were provided in snippets so I moved imports to the top of the file.

Me: let’s connect this to a frontend interface

CGPT:

<!DOCTYPE html>
<html>
<head>
<title>AI Chatbot</title>
</head>
<body>
<h1>AI Chatbot</h1>
<form id="chatbot-form">
<label for="message">Message:</label><br>
<input type="text" id="message" name="message"><br>
<input type="submit" value="Submit">
</form>
<div id="chatbot-response"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {…

--

--

CyberPunkMetalHead

x3 Top Writer and co-founder of Algo Trading Platform AESIR. I write about crypto, trading, tech and coding.