| llama_set_abort_callback | R Documentation |
Registers an R function that is called periodically during generation. If the function returns 'TRUE', the current decode operation is aborted. Pass 'NULL' to remove the callback.
llama_set_abort_callback(ctx, fn)
ctx |
Context handle returned by [llama_new_context] |
fn |
A zero-argument R function returning a logical scalar, or 'NULL' to clear. |
Note: only one callback is active globally — setting a new one replaces the previous one across all contexts.
No return value, called for side effects.
## Not run:
# Abort after 2 seconds
deadline <- Sys.time() + 2
llama_set_abort_callback(ctx, function() Sys.time() > deadline)
result <- llama_generate(ctx, "Tell me a long story", max_new_tokens = 500L)
llama_set_abort_callback(ctx, NULL)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.