get_default_chat() returns the ellmer Chat that dsprrr uses when neither
the call nor the module names one. set_default_chat() sets it for the
rest of the session; dsp_configure() does the same from a provider name.
clear_default_chat() forgets a chat that was created from an API key, so
the next call detects one again, for example after you change the key.
Value
get_default_chat() returns an ellmer Chat, or NULL when
create = FALSE and none is set. set_default_chat() returns the
previous default (or NULL) invisibly, and clear_default_chat()
returns NULL invisibly.
Details
How dsprrr chooses a chat
Each model call uses the first of these that is available:
The
.llmargument ofrun(),run_dataset(),evaluate(),compile()and the other functions that call models.The chat stored on the module, from the
chatargument ofmodule()and the other constructors.A chat set for a block of code with
with_lm()orlocal_lm().The default chat set with
set_default_chat()ordsp_configure()(stored inoptions(dsprrr.default_chat)).A chat created from the first API key found in the environment:
OPENAI_API_KEYgivesellmer::chat_openai(),ANTHROPIC_API_KEYgivesellmer::chat_anthropic()andGOOGLE_API_KEYgivesellmer::chat_google_gemini(), each with the provider's default model. It is created once, with a message naming the provider and model (setoptions(dsprrr.quiet = TRUE)to silence it), and reused untilclear_default_chat().
If none is available, the call fails with an error that explains how to
set one up. get_default_chat() returns the first of steps 3 to 5.
See also
Other configuration:
cache_stats(),
clear_cache(),
configure_cache(),
dsp_configure(),
dsprrr_sitrep(),
is_reasoning_model(),
with_lm()
Examples
# Building a chat makes no request, so this runs without an API key
luna <- ellmer::chat_openai(model = "gpt-6-luna")
previous <- set_default_chat(luna)
get_default_chat()$get_model()
#> [1] "gpt-6-luna"
# Restore the previous default (here: none)
set_default_chat(previous)
# Forget a chat detected from an API key
clear_default_chat()