Simon Willison’s Weblog


Weeknotes: A new llm CLI tool, plus automating my weeknotes and newsletter

4th April 2023

I started publishing weeknotes in 2019 partly as a way to hold myself accountable but mainly as a way to encourage myself to write more.

Now that I’m writing multiple posts a week (mainly about AI)—and sending them out as a newsletter—my weeknotes are feeling a little less necessary. Here’s everything I’ve written here since my last weeknotes on 22nd March:

(That list created using this SQL query.)

I’m going to keep them going though: I’ve had so much value out of the habit that I don’t feel it’s time to stop.

The llm CLI tool

This is one new piece of software I’ve released in the past few weeks that I haven’t written about yet.

I built the first version of llm, a command-line tool for running prompts against large language model (currently just ChatGPT and GPT-4), getting the results back on the command-line and also storing the prompt and response in a SQLite database.

It’s still pretty experimental, but it’s already looking like it will be a fun playground for trying out new things.

Here’s the 30s version of how to start using it:

# Install the tool
pipx install llm
# Put an OpenAI API key somewhere it can find it
echo 'your-OpenAI-API-key' > ~/.openai-api-key.txt
# Or you can set it as an environment variable:
# export OPENAI_API_KEY='...'
# Run a prompt
llm 'Ten names for cheesecakes'

This will output the response to that prompt directly to the terminal.

Add the -s or --stream option to stream results instead:

Animated GIF of a terminal window. Command is: llm 'Ten names for cheesecakes' -s - the output is 1. Classic New York Style Cheesecake 2. Raspberry Swirl Cheesecake 3. Lemon Meringue Cheesecake 4. Chocolate Chip Cookie Dough Cheesecake 5. Caramel Turtle Cheesecake 6. White Chocolate Raspberry Cheesecake 7. Blueberry Cheesecake 8. Peanut Butter Cup Cheesecake 9. Pumpkin Spice Cheesecake 10. Key Lime Cheesecake

Prompts are run against ChatGPT’s inexpensive gpt-3.5-turbo model by default. You can use -4 to run against the GPT-4 model instead (if you have access to it), or --model X to run against another named OpenAI model.

If a SQLite database file exists in ~/.llm/log.db any prompts you run will be automatically recorded to that database, which you can then explore using datasette ~/.llm/log.db.

The following command will create that database if it does not yet exist:

 llm init-db

There’s more in the README.

There are plenty of other options for tools for running LLM prompts on your own machines, including some that work on the command-line and some that record your results. llm is probably less useful than those alternatives, but it’s a fun space for me to try out new ideas.

Automating my weeknotes

I wrote at length about how I automated most of my newsletter using an Observable notebook and some Datasette tricks.

I realized the same trick could work for my weeknotes as well. The “releases this week” and “TILs this week” sections have previously been generated by hand, so I applied the same technique from the newsletter notebook to automate them as well. is the notebook. It fetches TILs from my TILs Datasette, then grabs releases from this page on GitHub.

It also fetches the full text of my most recent weeknotes post from my blog’s Datasette backup so it can calculate which releases and TILs are new since last time.

It uses various regular expression and array tricks to filter that content to just the new stuff, then assembles me a markdown string which I can use as the basis of my new post.

Here’s what that generated for me this week:

Releases since last time

  • datasette-explain 0.1a1—2023-04-04
    Explain and validate SQL queries as you type them into Datasette
  • llm 0.2—2023-04-01
    Access large language models from the command-line
  • datasette-graphql 2.2—2023-03-23
    Datasette plugin providing an automatic GraphQL API for your SQLite databases

TIL since last time