diff --git a/README.md b/README.md index 3d35971..cc89e6f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/). For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter). -_1840 TILs and counting..._ +_1841 TILs and counting..._ See some of the other learning resources I work on: @@ -732,6 +732,7 @@ If you've learned something here, support my efforts writing daily TILs by ### LLM - [Count Number Of Tokens In A File](llm/count-number-of-tokens-in-a-file.md) +- [Include A File With Message To `ant`](llm/include-a-file-with-message-to-ant.md) - [Send cURL To Claude Text Completion API](llm/send-curl-to-claude-text-completion-api.md) - [Use The llm CLI With Claude Models](llm/use-the-llm-cli-with-claude-models.md) diff --git a/llm/include-a-file-with-message-to-ant.md b/llm/include-a-file-with-message-to-ant.md new file mode 100644 index 0000000..1544e31 --- /dev/null +++ b/llm/include-a-file-with-message-to-ant.md @@ -0,0 +1,50 @@ +# Include A File With Message To `ant` + +The [Anthropic CLI tool](https://github.com/anthropics/anthropic-cli) (`ant`) +allows including files, such as images, directly in the message being sent to +the model. This is done with the `@` symbol followed by a relative path to the +image on the file system. + +I have a file `parameterized-behavioral-tests.png` in my current directory that +I'd like to include. In the `content` array of the message I include an object +of type `image` along with some `source` metadata. Within `source` the image +file is referenced with the `data` field. + +With that set, I then include a `text` object with my prompt asking for alt text +of this image. + +```bash +❯ ant messages create \ + --model claude-opus-5 \ + --max-tokens 1024 \ + --message '{role: user, content: [ + {type: image, source: {type: base64, media_type: image/png, data: "@./parameterized-behavioral-tests.png"}}, + {type: text, text: "Produce a concise, but descriptive alt text for this image."} + ]}' \ + --transform 'content.#(type=="text").text' --raw-output + +A hand-drawn style diagram comparing two testing approaches, split by a vertical +line. + +On the left, under the heading "Behavioral Tests," is a single column of six +rounded rectangular test rows: four outlined in green with green check-mark +icons (passing) and two outlined in red with red X icons (failing), each +containing black scribble lines representing text. + +On the right, under the heading "Parameterized Behavioral Tests," a bracketed +list of three purple parameter symbols — a circle, a triangle, and a diamond — +sits at the top, with arrows pointing down to three separate columns of six test +rows each. Every row in a column is tagged with its corresponding parameter +shape on the right edge. The circle column shows all six rows passing (green +with check marks). The triangle column shows three passing and three failing +(red with X marks). The diamond column shows five passing and one failing. The +illustration conveys that a single behavioral test, when parameterized, expands +into multiple variants whose pass/fail outcomes can differ per parameter. +``` + +This is for [the image toward the top of this post on parameterized tests in +pytest](https://www.visualmode.dev/parameterize-a-fixture-instead-of-a-test-case-with-pytest). +The description is a bit wordier than I would have liked, but it is spot on. It +is both visually descriptive and conveys what is being conceptually illustrated. + +This whole thing was 3800 input tokens, 328 output tokens, and cost ~$0.02.