Skip to main content

AE 17: Introduction to LLMs

Suggested answers

Application exercise
Answers
Modified

November 5, 2026

01-hello-llm

library(ellmer)

# ---- OpenAI ----
chat_gpt <- chat_openai()
chat_gpt$chat(
  "I'm in this class to learn about programming with LLMs and ellmer!",
  "Write a brief inspirational message for me."
)

# ---- Anthropic ----
chat_claude <- chat_claude()
chat_claude$chat(
  "I'm in this class to learn about programming with LLMs and ellmer!",
  "Write a short poem to celebrate."
)

02-word-game

library(ellmer)

chat <- chat_openai(
  system_prompt = paste(
    "We are playing a word guessing game.",
    "At each turn, you guess the word and tell us what it is."
  )
)

chat$chat(
  "In British English, guess the word for a person who lives next door."
)

chat$chat("What helps a car move smoothly down the road?")


# Compare with...
chat <- chat_openai()
chat$chat("What helps a car move smoothly down the road?")

05-live

library(ellmer)

# Your job: Get information on how to use the `tidyr::pivot_wider()` function
chat <- chat_openai()

# Converse with the chatbot in your console.
live_console(chat)

# After a bit, exit the chat and try chatting in a Shiny app.
live_browser(chat)

Acknowledgments