GPT Intern: Infinite Loop
Using GPT is like having a hardworking, if slow, intern that’s good at Googling things.
Earlier today I was trying to write a simple Flask echo server – I’m not familiar with Flask – to echo a query string back at the user. I spent a comparable amount of time on my GPT prompt as I would have searching Google and I got back this nice piece of code,
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def echo():
query = request.args.get('q', '')
return query
if __name__ == '__main__':
app.run()
Pretty good!1 Except I specifically asked it to make sure the content-type is text/plain. Upon testing, it seems Flask returns text/html in this case.
I notified my intern of this mistake and…
@app.route('/')
def echo():
query = request.args.get('q', '')
return Response(query, mimetype='text/plain')
Again, this is pretty good. I might’ve found a simple echo server just by Googling but the specific text/plain requirement might’ve required pouring through some more documentation.
Unfortunately my devtools complains that /favicon.ico
gives 404. This is not
actually an issue, but while I’m at it why not try to produce a quick fix.
Intern?
@app.route('/favicon.ico')
def favicon():
return app.send_static_file('favicon.ico')
Like a true intern, GPT did what I asked not what I wanted. That’s my fault of course. How about inlining the favicon data?
@app.route('/favicon.ico')
def favicon():
blank_favicon = (
'AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIjAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAA
Uh oh, I broke my intern. Intern, are you okay?
@app.route('/favicon.ico')
def favicon():
favicon_image = Image.new('RGBA', (16, 16), (0, 0, 0, 0)) # Creating a blank 16x16 image
favicon_data = BytesIO() # Creating a BytesIO object to store the image data
favicon_image.save(favicon_data, format='PNG') # Save the blank image as PNG to the BytesIO object
favicon_data.seek(0) # Reset the stream position to the beginning
return favicon_data.getvalue(), 200, {'Content-Type': 'image/png'}
I’ll note here GPT is actually regenerating the full code every time, which is useful for copy and pasting. It gets the imports correct. But…
ModuleNotFoundError: No module named 'PIL'
This is my fault and not my intern’s. I don’t want dependencies other than Flask! I also want ico format for maximal compatibility.2
@app.route('/favicon.ico')
def favicon():
blank_favicon_data = (
'AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIjAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
Like before this goes on forever (although Chat GPT knows to cut itself off before long).
I turned to my other intern, Google, who recommended http://transparent-favicon.info/.
$ curl http://transparent-favicon.info/favicon.ico 2>/dev/null | base64
AAABAAEAEBACAAEAAQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/
/wAA//8AAP//AAD//wAA//8AAP//AAD//wAA
I, of course, had to deal with the indignity of turning this knowledge into code myself.
My Other Intern
Programming without Google would be difficult, but I suppose if there were no Google all us code monkeys would be hampered in the same way, and standards would just be lower.3 ChatGPT has been useful, but less useful than Google.
GPT is great at boilerplate. If you’re on the beaten path it works really well. It has weird edge cases though: too much repetition and it will keep up that repetition forever. This flask echo server is representative of my experience with ChatGPT.
Would this issue be fixed if I paid for premium? Maybe! How about an LLM more suited toward code, like Copilot? Maybe! I haven’t used Copilot. It would be exciting if the solution to these deficiencies is simply to throw more computing power at them. As far as I can tell we’re at the beginning of the road for these technologies.
Anyone reading this has probably read a thousand ChatGPT blog posts before. But, I’m just starting to use it, and my experience is even the free version gives you enough of a productivity boost that not using it would be to fall behind.
-
Google would’ve given me this which, while almost the same, GPT is more to the point and matches my requirements, since I specifically specified to use
q
. ↩︎ -
Or maybe I don’t. Sometimes interns know more than you, and for my knowledge returning a png might be the preferred ways to do things. ↩︎
-
I don’t mean Google specifically. DuckDuckGo and Bing sometimes give better results. ↩︎