View source: R/LLM_robust_utils.R
call_llm_robust | R Documentation |
Wraps call_llm
to handle rate-limit errors (HTTP 429 or related
"Too Many Requests" messages). It retries the call a specified number of times,
now using exponential backoff. You can also choose to cache responses if you do
not need fresh results each time.
call_llm_robust(
config,
messages,
tries = 3,
wait_seconds = 10,
backoff_factor = 2,
verbose = FALSE,
json = FALSE,
memoize = FALSE
)
config |
An |
messages |
A list of message objects (or character vector for embeddings). |
tries |
Integer. Number of retries before giving up. Default is 3. |
wait_seconds |
Numeric. Initial wait time (seconds) before the first retry. Default is 10. |
backoff_factor |
Numeric. Multiplier for wait time after each failure. Default is 2. |
verbose |
Logical. If TRUE, prints the full API response. |
json |
Logical. If TRUE, returns the raw JSON as an attribute. |
memoize |
Logical. If TRUE, calls are cached to avoid repeated identical requests. Default is FALSE. |
The successful result from call_llm
, or an error if all retries fail.
## Not run:
# Basic usage:
robust_resp <- call_llm_robust(
config = my_llm_config,
messages = list(list(role = "user", content = "Hello, LLM!")),
tries = 3,
wait_seconds = 10,
memoize = FALSE
)
cat("Response:", robust_resp, "\n")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.