Sets a scoped LLM override that lasts until the calling function exits. Useful for functions that need to ensure a specific LLM is used for all internal dsprrr calls.
Usage
local_lm(lm, .env = parent.frame())Details
This function uses withr::defer() to ensure cleanup when the calling
function exits, even if an error occurs. For a block-based alternative,
see with_lm().
Examples
if (FALSE) { # \dontrun{
my_analysis <- function(data) {
# All dsprrr calls in this function will use Claude
local_lm(ellmer::chat_claude())
# These calls don't need .llm parameter
summary <- run(module(signature("data -> summary")), data = data)
insights <- run(
module(signature("summary -> insights")),
summary = summary
)
insights
}
# The scoped LM is automatically cleared when my_analysis() returns
result <- my_analysis(my_data)
} # }