Skip to content

Designed for tidyverse pipelines. Sends each element of x to the model with a strict instruction to return exactly one label from categories.

Usage

classify_llm(
  x,
  categories,
  model = "gpt-4o-mini",
  temperature = 0,
  batch_size = 1L,
  delay = 0,
  verbose = FALSE
)

Arguments

x

Character vector to classify.

categories

Character vector of allowed categories (labels).

model

OpenAI model name. Default: "gpt-4o-mini".

temperature

Numeric in 0,1; default 0 for deterministic outputs.

batch_size

Integer; number of elements per API call batch. Default 1.

delay

Seconds to sleep between batches to avoid rate limits. Default 0.

verbose

Logical; print progress info. Default FALSE.

Value

A factor with levels = categories, aligned to input length.

Examples

if (FALSE) { # \dontrun{
Sys.setenv(OPENAI_API_KEY = "sk-...")
classify_llm(
  x = c("siamese kitty","golden retriever","parakeet"),
  categories = c("cat","dog","bird")
)
} # }