Entropic Thoughts

q What do I title this article?

q What do I title this article?

I have been an llm skeptic. I evaluated them early on1 Before ChatGPT, to give it context!, but at the time my experience was that useful results required a lot of work. A lot of things coincided, and I decided to give llm​s another shot.

I created the following shell script, named it just q, and placed it in my path.2 This calls out to Simon Willison’s amazing llm cli tool, which needs a separate one-time setup.

#!/bin/sh

llm -s "Answer in as few words as possible. Use a brief style with short replies." -m claude-3.5-sonnet "$*"

It has since become one of my most used shell scripts ever!3 I think the system prompt is a big part of it. By default, llm​s are very wordy.

Asking stupid questions right where we are

This lets us ask any question we want, right from within the context we’re in. Maybe we’re in the middle of diagnosing a problem in a project, and we can’t remember how to start a container with a different entrypoint. So we ask just that, but prefixed with the letter q:

[user@host ~]$ q How do I run Docker with a different entrypoint to that in the container?
To run Docker with a different entrypoint:

1. Use the --entrypoint flag
2. Specify the new entrypoint
3. Add the image name
4. (Optional) Add any command arguments

Example:
```
docker run --entrypoint /bin/bash my-image
```

This overrides the default entrypoint with /bin/bash.

We get an answer without breaking our flow, and we won’t be judged however stupid the question is.

Asking longer questions with a heredoc

If we want to ask a longer question, we can do that with a heredoc:

[user@host ~]$ q <<'EOF'
> I have the following Perl code
>
>     @content[sort { $dists[$a] <=> $dists[$b] } 0..$#content];
>
> What does it do?
EOF
This Perl code sorts the @content array based on the corresponding
values in the @dists array in ascending order. It uses a custom sort
function to compare elements of @dists and reorders @content
accordingly.

I try to avoid designing software such that it needs boilerplate code, but when I’m forced to write boilerplate code, I use these heredoc questions a lot for simple but tedious modifications. by copy-pasting in definitions and asking for a change. (“Please create a function that converts between the output of this function and the input to this” is a good one.)

Including the contents of some file in the question

We can even supply context from the files we are working on:

[user@host ~]$ cat LICENCE | q What licence is this?
This is the ISC (Internet Systems Consortium) License. It's a
permissive free software license similar to the MIT and BSD
licenses.

When I piped in the contents of this article and ran the command in the title, I got the suggestion “Quick llm queries with a simple shell script” which is descriptive but perhaps a tad too long.4 In a meta twist, I tried running the command again after typing up this paragraph, and it did shorten its suggestion to “Quick llm queries with ‘q’ script” which is still too long for an article title, in my opinion.

Bonus scripts: qe and qs

I actually have more than one of these scripts. I also have

  • one called qe which is exactly the same but specifying claude-3-opus as the model (qe means q-but-expensive.)
  • one called qs which specifies claude-3-haiku as the model (qs means q-but-cheap – I don’t know how cheap became s.)

These have become a great way to dip my toes into utilising llm​s more in my daily work, and I’m starting to sense where they are powerful and where they still have some ways to go.

New here? I am only just starting to discover what llms can do, and I intend to write more as I learn more. You should subscribe to receive weekly summaries of new articles by email. If you don't like it, you can unsubscribe any time.

Appendix A: selection of historic queries

Here are some of my past q invocations taken from my shell history:

  • git grep -n WeirdObject | q Where is WeirdObject defined?
    • Again, piping context into the query.
  • q ’If I asked you to generate 20 random lines of code that look like something one might find in the Linux kernel, what would you print? I fully undrstand you don’t have access to the real kernel source code, so you’d be making stuff up and that is okay. Please put them in <scratchpad>. Then count how many of them are assignment statements (including things like memset).’
    • This was more of an experiment, but as long as it is convinced I know it can’t look up the real source code, it does a really good job of generating code that looks like it.
  • q What is a better word for self-development used in professional contexts? Not strictly about professional development, but just becoming a better person more generally.
    • Unsurprisingly, llm​s are really good at language.
  • q ’What is a software developer paid per minute? Show your work in <scratchpad> then report the result.’
    • I sort of knew the answer to this already, but asked anyway to double-check my work.
  • q Suggest 20 silly-sounding software-development sounding task, a little like \“reticulating splines\” but not that, and not as manual
  • q Is there an optic in Control.Lens to add an element to a list?
    • It taught me about the cons optic, but I wasn’t able to immediately figure out how to use it.
  • q How do I use the cons optic from Control.Lens to add an element to a list inside another datatype?
    • It knows a surprising amount of somewhat esoteric Haskell!
  • q \“I do not care about collecting an audience, BMAC is enough.\” What does BMAC mean?
    • Sure enough, it – as opposed to me – knew it meant Buy Me A Coffee.
  • q Can you give me the normal width unicode box drawing characters in the shape of boxes? I.e. it is fine to duplicate characters etc. to make a sensible-looking box. The reason I want this is to make it easier to copy-paste the characters I need in the right places.
    • This is surprisingly hard to find online.
  • q ’$ find bin -exec “perl -lpE ‘s/Two Wrongs/Entropic Thoughts/’ {}” find: missing argument to -exec. What is wrong? Thanks.’
    • It did indeed pick up on the fact that I had forgot about the semicolon!
  • q How do I combine many PDL vectors into a matrix?
    • It gets that I’m talking Perl, which is neat.
  • qe How do I compute the correlation between rank and a binary tag applied to some of the elements? Can you give a concrete formula for the point-biserial correlation?
    • This required Opus when I tried, but it actually presented the computation in a much more friendly way than Wikipedia, which is my other go-to source for these kinds of things.
  • q How do I interpolate a perl variable in a regex without accidentally entering a $ anchor?
    • It would have been trivial to google this, but it is more convenient to ask it of the terminal I’m in anyway.