## --- Vector input ------------------------------------------------------
if (FALSE) {
cfg <- llm_config(
provider = "openai",
model = "gpt-4.1-nano",
api_key = Sys.getenv("OPENAI_API_KEY"),
temperature = 0
)
words <- c("excellent", "awful", "average")
llm_fn(
words,
prompt = "Classify sentiment of '{x}' as Positive, Negative, or Neutral.",
.config = cfg,
.system_prompt = "Respond with ONE word only."
)
## --- Data-frame input inside a tidyverse pipeline ----------------------
library(dplyr)
reviews <- tibble::tibble(
id = 1:3,
review = c("Great toaster!", "Burns bread.", "It's okay.")
)
reviews |>
llm_mutate(
sentiment,
prompt = "Classify the sentiment of this review: {review}",
.config = cfg,
.system_prompt = "Respond with Positive, Negative, or Neutral."
)
}
Run the code above in your browser using DataLab