Skip to contents

apply_best_config() copies the best parameters, the demonstrations and the optimization result from an optimized module to another module, for example to reuse a compiled configuration on a module with a different chat.

Usage

apply_best_config(source, target = NULL, include = c("all", "params", "demos"))

Arguments

source

An optimized module, returned by compile() or modified by optimize_grid().

target

The module to update. It is modified in place. If NULL, a fresh copy of source is created and updated.

include

What to copy: "all" (the default), "params" (the best parameters, such as temperature) or "demos" (the demonstrations).

Value

The updated target module, invisibly.

Examples

classifier <- module(signature("text -> sentiment"))
trainset <- data.frame(
  text = c("I love it!", "Terrible experience", "It's okay"),
  sentiment = c("positive", "negative", "neutral")
)
compiled <- compile(classifier, LabeledFewShot(k = 2L), trainset)

fresh <- module(signature("text -> sentiment"))
apply_best_config(compiled, fresh, include = "demos")
length(fresh$demos)
#> [1] 2