GPT4 should be part of your toolkit
On March 24 I wrote GPT is revolutionary. On March 27 I got access to GPT4.1 Now that I've used it for a month, I'm firmly in the "this is the greatest thing ever" camp. And, much like my experience at Burning Man, I'm finding a not-insignificant number of my fellow campers run around with their butts showing. GPT4 needs advocates that aren't either SEO marketers or AGI fanatics, so here's why I like it so much!
I first tried it out when writing Everything's an API: I wanted to cite an interesting case I knew about but couldn't find the sources I needed. So, as an experiment, I asked GPT4:
Now I should make clear that the AI got the details wrong. The article was written by Gary Taubes, not Adrian Thompson, and it was published in 1998.2 However, it got the name of the article right! I hadn't been able to find the article by searching, and GPT4 just... gave it to me.
That's how I use GPT best, asking for things that are hard to search for but easy to check. I raised the same use case with ChatGPT but it often got things too wrong to be worth the effort. GPT4 isn't perfect, but it's good enough to be a springboard.
Other research questions:
- "How to check if computer is x86 or x64"
- "What US organization tracks statistic X, and what is their website?"
- For my April Cools post, finding the names of the international treaty that prevents selling cultural artifacts, then finding the specific UK law.
- Finding the first paper to introduce Powershell, followed by the press released that renamed Monad to Powershell
A calculator for words
If you're using GPT4 through ChatGPT Plus, you're missing out. First of all, the API's a lot cheaper: you'd have to go through over 300,000 tokens to match the monthly cost of Chat. Second, you can set the chat's "system message", an out-of-band channel that instructs the AI how to respond. This makes GPT4 an extraordinary calculator for words.
I like to think of language models like ChatGPT as a calculator for words.
This is reflected in their name: a “language model” implies that they are tools for working with language. That’s what they’ve been trained to do, and it’s language manipulation where they truly excel. — Simon Willison
I use GPT4 as a word calculator all of the time. In I really like PowerShell I used it to quickly add documentation links to each mentioned cmdlet:
Afterwards I went through and clicked all of the links, and only one of them was wrong. Another case of hard (or annoying) to do, easy to check.
Another use case: I hate copying text from academic papers because I have to fix up lots of extra newlines and soft hyphens. I got GPT4 to fix them up with the system message "Take the user input and convert it to a single line. Remove the hyphens in broken words."
I really like using GPT for text transforms because transforms, as a rule, are both repetitive and hard to automate.
Making a programming flunky
So these are some day-to-day things I need it for, but I've got a weird job, more a researcher and writer most days than an engineer. So how do we make GPT4 good for programming?
Well first let's make it a bit easier to use programmatically. If you install the OpenAI python SDK, you also get a CLI. I wrapped it in a shell script:
$ ask "Git search for diffs that added or removed a string"
To search for diffs that added or removed a specific string in a Git repository,
you can use the `git log` command with the `-S` option followed by the string you want to search for.
Here's the syntax:
git log -S 'search_string' --patch
You can also use the `-G` option with a regular expression to search for diffs
that added or removed lines that match the given pattern:
git log -G 'regular_expression' --patch
Now this might not necessarily be correct or even close to correct. But once again we're in "easy to check" territory: you can quickly try to see if it works, or look up the git log
docs and search for -S
.3
(Though in Google's defense, for the same string the first result also answers the question.)
Quick lookups are good, but the big draw of Chat completion is persistent conversations. You can query GPT4, get a response, and then ask something about the response and get something useful back. For writing programs this is especially important for dealing with cutoffs: if GPT4 gives you the first half of a program, you can pass in your original query and the first half and it will finish generating the second half.
But again, using the online playground isn't very programmery, now is it? Better to use a text editor. I wrote a small Lua script to call GPT from inside neovim.
@@@
is the delimiter: @@@s
is a system message, @@@u
a user message, and @@@a
an AI, any other letter is ignored. It's a little silly but I like that @@@c
acts like a comment.
Now let's really have some fun.
Automating everything
Last week I ran a corporate TLA+ workshop and as part of the prep I reorganized the topic order.4 The hardest part of revising the workshop is always making new slides. I hate slides. They take forever to make, they're terrible for presenting information, and it's hard for students to check back on. I only use them because I can't think of anything better to do.
Anyway, last week I decided screw it no more powerpoint, I'm writing everything live! I'd make a lecture.md
file and sync it to an s3 bucket on every save. That way I could run the entire workshop without leaving vscode. The only challenge, then, would be writing the watcher script. I could probably whip it up myself in an hour or two, but I decided first to see if GPT4 could handle it.
SYSTEM: Provide python code only. Do not provide any other output. You have access to the AWS python library.
USER: Give me a python script that watches a file and every time it changes, upload the new version to an AWS s3 object, replacing the old object.
After a bit of convo it got me this:
import time
import hashlib
import os
import boto3
from botocore.exceptions import NoCredentialsError
def upload_modified_file(file_path, bucket_name, s3_object_key, last_uploaded_hash):
with open(file_path, "rb") as file:
file_hash = hashlib.md5(file.read()).hexdigest()
if file_hash == last_uploaded_hash:
return last_uploaded_hash
try:
s3.upload_file(file_path, bucket_name, s3_object_key)
print(f"File uploaded to {bucket_name}/{s3_object_key}")
return file_hash
except NoCredentialsError:
print("Please check your AWS credentials.")
return last_uploaded_hash
except Exception as e:
print(e)
return last_uploaded_hash
# Set up S3 client and initialize variables
s3 = boto3.client("s3")
bucket_name = "your-bucket-name"
file_path = "path/to/your-file.txt"
s3_object_key = "desired-object-key
polling_interval = 1
last_modified_time = 0
last_uploaded_hash = ""
# Main polling loop
try:
while True:
current_modified_time = os.path.getmtime(file_path)
if current_modified_time != last_modified_time:
last_uploaded_hash = upload_modified_file(file_path, bucket_name, s3_object_key, last_uploaded_hash)
last_modified_time = current_modified_time
time.sleep(polling_interval)
except KeyboardInterrupt:
print("Exiting...")
Is this good code? Not really. I'd even say it's pretty crummy code. If I wrote my own python script from ground up, it would have been a lot better. But it would also have taken a lot longer, because I'd have to spend time looking up all the relevant APIs and libraries. It took me a minute to generate this code and it solves my problem.
(The workshop went really well and the students appreciated No Slides.)
GPT4 is useful because it's flexible
So to summarize, that's four ways to use GPT4:
- Research tool
- Word calculator
- Fast stackoverflow
- Script generator
There's a lot of variety there, and that's not even all the things I regularly do with it!5 But what's really cool is all the things I haven't done with it. Quinn Wilton told me how she uses it for test case generation and analyzing objdump output. Jeremy Kun has a thread on ways GPT4 helped him (and ways it hasn't). Simon Willison shares tons of uses in his TILs, like comparing different APIs and generating alt text.
I've never seen a tool more flexible than GPT4. Just the sheer variety of things you can do with it makes it worth using. No matter who you are, if your job sits you at a computer all day then there's gonna be something GPT4 can do for you.
At the same time, you have to know its limits. The AI is often wrong and you need to verify everything you get back. So focus on the problems that are hard to do, but easy to check.
TLA+ Workshop
I'm running a public TLA+ workshop in May. Use the code C0MPUT3RTHINGS
for 15% off!
-
Go figure. ↩
-
And I left the date error in the actual newsletter, which goes to show just how careful I need to be fact-checking the AI's claims. ↩
-
"But you shouldn't try untrusted code." True, but I know what
git log
does, and I'm pretty sure adding a flag won't nuke my computer. If the output was an unrecognized command you bet I'll be more cautious. As always, nothing can replace the importance of expertise. ↩ -
If you're morbidly curious I moved the introduction of liveness and fairness much earlier so we're covering it when students are still fresh and have brain juice left ↩
-
One use I love but didn't fit in earlier: writing code for really niche DSLs. I regularly use it to generate TikZ because writing TikZ from scratch is The Worst ↩
If you're reading this on the web, you can subscribe here. Updates are once a week. My main website is here.