Programming with LLMs in R and Python
posit::conf(2026)
2026-09-14
It’s okay to (mostly) treat LLMs as black boxes.
We’re not going to focus on how they work internally
Just try it! When wondering if an LLM can do something,
experiment rather than theorize
You might think they could not possibly do things
that they clearly can do today
And you might think surely they can do something
that it turns out they’re terrible at
Photo by National Cancer Institute on Unsplash
We’re going to focus on the core building blocks.
All the incredible things you see AI do
decompose to just a few key ingredients.
Photo by Jaroslaw Glogowski on Unsplash


R

Python
Most LLMs are accessible through HTTP APIs
ellmer
Messages have roles.
| Role | Description |
|---|---|
system |
Instructions that set the behavior of the assistant |
user |
Messages from the person interacting with the assistant |
assistant |
The AI model’s responses to the user |
ellmer
ellmer
02_conversationSet up a chat with this system prompt:
Answer in as few words as possible.
Ask: What creates an Anthropic chat in ellmer and chatlas?
Ask: What about OpenAI?
Then, create a new chat with no system prompt and ask only the second question: What about OpenAI?
How do the answers to 3 and 4 differ? Why?
clearbot👨💻 _demos/03_clearbot/app.py
System prompt:
First question:
Second question:
Photo by Andy Kelly on Unsplash

Photo by Marija Zaric on Unsplash
The LLM doesn’t remember anything between requests
For each response, the LLM receives the conversation history again
The LLM reconstructs the “conversation” from that history
Chatting with a Generative Pre-trained Transformer
LLM → Large Language Model
If you read everything
ever written…
Books and stories
Websites and articles
Poems and jokes
Questions and answers
…then you could…
un|con|ventionaltoken-possibilities👨💻 _demos/04_token-possibilities/app.R
| Console | Browser | |
|---|---|---|
![]() |
live_console(chat) |
live_browser(chat) |
![]() |
chat.console() |
chat.app() |
05_liveYour job: write a groan-worthy roast of Hadley Wickham
Bonus points for puns, rhymes, and one-liners
Don’t be mean
Share your best with a neighbor.