Queries a language model API with structured neuroscience prompts (e.g., IDP-domain consistency, region-network assignment) and parses the output into a clean data frame.

assess_prompt(
  df,
  text_cols,
  context_col = NULL,
  prompt = "You are a neuroscientist. Return JSON.",
  backend = c("groq", "openrouter"),
  api_key_env = NULL,
  model = NULL,
  required_fields = c("short_form", "long_form"),
  user_input_prompt = "Return structured JSON output.",
  collapse_fn = function(x) paste(na.omit(x), collapse = ", "),
  max_retries = 5,
  retry_delay_base = 2,
  jitter = TRUE,
  temperature = 0.1,
  parallel = FALSE,
  .options_furrr = furrr::furrr_options(),
  cache_dir = NULL,
  verbose = TRUE,
  skip_api_key_check = FALSE
)

Arguments

df

A data frame containing input data (domains, IDPs, regions, etc.).

text_cols

Character vector, column names to collapse into the user query (e.g. IDPs, regions).

context_col

Character, optional column name providing task context (e.g., domain). Default: NULL.

prompt

Character, system prompt to set context. Default: "You are a neuroscientist. Return JSON."

backend

Character, API backend ("groq", "openrouter"). Default: "groq".

api_key_env

Character, environment variable storing the API key. Default: NULL.

model

Character, model name. Default: NULL (uses backend default).

required_fields

Character vector, keys required in parsed API response. Default: c("short_form", "long_form").

user_input_prompt

Character, additional user prompt text. Default: "Return structured JSON output."

collapse_fn

Function, how to collapse multiple text columns. Default: function(x) paste(na.omit(x), collapse = ", ").

max_retries

Integer, maximum API retry attempts. Default: 5.

retry_delay_base

Numeric, base delay (seconds) for exponential backoff. Default: 2.

jitter

Logical, add jitter to retry delays. Default: TRUE.

temperature

Numeric, sampling temperature (0–1). Default: 0.1.

parallel

Logical, use parallel processing with furrr::future_map. Default: FALSE.

.options_furrr

List, options for furrr::future_map. Default: furrr::furrr_options().

cache_dir

Character, directory for caching API responses. Default: NULL.

verbose

Logical, print debug information. Default: TRUE.

skip_api_key_check

Logical, if TRUE, skip API key validation (useful for testing). Default: FALSE.

Value

A tibble combining original data with parsed model outputs.