llm_fn: Apply an LLM prompt over vectors/data frames

View source: R/LLMR_tidy.R

llm_fnR Documentation

Apply an LLM prompt over vectors/data frames

Description

Apply an LLM prompt over vectors/data frames

Usage

llm_fn(
  x,
  prompt,
  .config,
  .system_prompt = NULL,
  ...,
  .return = c("text", "columns", "object")
)

Arguments

x

A character vector or a data.frame/tibble.

prompt

A glue template string. With a data-frame you may reference columns ({col}); with a vector the placeholder is {x}.

.config

An llm_config object.

.system_prompt

Optional system message (character scalar).

...

Passed unchanged to call_llm_broadcast() (e.g. tries, progress, verbose).

.return

One of c("text","columns","object"). "columns" returns a tibble of diagnostic columns; "text" returns a character vector; "object" returns a list of llmr_response (or NA on failure).

Value

For generative mode:

  • .return = "text": character vector

  • .return = "columns": tibble with diagnostics

  • .return = "object": list of llmr_response (or NA on failure) For embedding mode, always a numeric matrix.

See Also

llm_mutate(), setup_llm_parallel(), call_llm_broadcast()

Examples

if (interactive()) {
  words <- c("excellent","awful")
  cfg <- llm_config("openai","gpt-4o-mini", temperature = 0)
  llm_fn(words, "Classify '{x}' as Positive/Negative.",
         cfg,
         .system_prompt="One word.",
         .return="columns")
}

LLMR documentation built on Aug. 26, 2025, 9:08 a.m.