Skip to contents

Re-executes a coding task from a qlm_coded object, optionally with modified settings. If no overrides are provided, uses identical settings to the original coding: both the execution arguments and the arguments the original run passed to ellmer::chat(), such as params and api_args. Credentials and endpoint settings are an exception, and are carried over only while the endpoint itself is unchanged.

Usage

qlm_replicate(
  x,
  ...,
  codebook = NULL,
  model = NULL,
  batch = NULL,
  backfill = NULL,
  name = NULL,
  notes = NULL
)

Arguments

x

A qlm_coded object.

...

Optional overrides passed to qlm_code(), such as params, api_args, or max_active. Any setting not overridden is restored from the original run when the endpoint is unchanged, including the arguments it passed to ellmer::chat(). An endpoint is identified by both the provider prefix and base_url (an explicit base_url = NULL, meaning the provider's default host, counts as a change of endpoint), since every provider ellmer has no chat_*() for is reached as openai_compatible/<model> — so Qwen through Alibaba Model Studio and Kimi through Moonshot share a prefix while being different services with different credentials. When either changes, only portable chat settings (params and echo) are carried over; supply credentials, endpoint settings and other endpoint-specific arguments explicitly. An informational message names inherited arguments that were omitted and not explicitly replaced. Registered tools are carried like the rest: kept on the same endpoint, since a hosted tool belongs to its provider, and dropped with the message when it changes; pass tools to replace them. An object read back from a trail records its tools by description and configuration only, and those are not sent either.

codebook

Optional replacement codebook. If NULL (default), uses the codebook from x.

model

Optional replacement model (e.g., "openai/gpt-4o"). If NULL (default), uses the model from x.

batch

Optional logical to override batch processing setting. If NULL (default), uses the batch setting from x. Set to TRUE to use batch processing or FALSE to use parallel processing, regardless of the original setting.

backfill

Logical, integer, or NULL; controls backfilling after the replication. NULL (default) replays the passes recorded on x, using the same models and overrides in the same order. FALSE or 0 performs no backfill. TRUE runs a fresh backfill with the replication's model and the default number of passes, currently two; a positive integer runs at most that many fresh passes. A fresh backfill does not reproduce a different model used by the parent's recorded passes. If a replayed pass fails outright, the replication and any earlier recoveries are retained, the failure is recorded, and no later passes are replayed.

name

Optional name for this run. If NULL, defaults to the model name (if changed) or "replication_N" where N is the replication count.

notes

Optional character string with descriptive notes about this replication. Useful for documenting why this replication was run or what differs from the original. Default is NULL.

Value

A qlm_coded object with run$parent set to the parent's run name.

Details

The coding path is reproduced from the path the original run actually took, not the structured mode it requested: a run that asked for "auto" and fell back to JSON mode replicates as "json", so that an intermittently conforming endpoint cannot quietly skip the local validation the original relied on. Pass structured explicitly to override. When the endpoint changes, provider or base_url, the path is chosen afresh for it. By the same rule, a parent that was completed with qlm_backfill() has its passes replayed on the replication, so the two are complete on the same terms; see backfill.

See also

qlm_code() for initial coding, qlm_compare() for comparing replicated results, qlm_backfill() to re-code only the units a run failed on.

Examples

if (FALSE) { # \dontrun{
# First create a coded object
texts <- c("I love this!", "Terrible.", "It's okay.")
coded <- qlm_code(texts, data_codebook_sentiment, model = "openai/gpt-4o-mini", name = "run1")

# Replicate with same model
coded2 <- qlm_replicate(coded, name = "run2")

# Compare results
qlm_compare(coded, coded2, by = "sentiment", level = "nominal")
} # }