| Title: | AI-Powered Blocks for 'blockr.core' |
|---|---|
| Description: | Provides AI-powered functionality as blocks for 'blockr.core'. Enables integration with various AI services and models to enhance data analysis workflows. |
| Authors: | Nicolas Bennett [aut], Antoine Fabri [aut], Christoph Sax [aut, cre] |
| Maintainer: | Christoph Sax <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.1 |
| Built: | 2026-05-26 15:10:51 UTC |
| Source: | https://github.com/cynkra/blockr.ai |
Replaces the default ctrl_block with an AI chat interface. Users can describe what they want in natural language and the LLM will configure the block parameters.
ai_ctrl_block() ai_ctrl_ui(id, x) ai_ctrl_server(id, x, vars, data, eval)ai_ctrl_block() ai_ctrl_ui(id, x) ai_ctrl_server(id, x, vars, data, eval)
id |
Namespace ID |
x |
Block object |
vars |
Reactive state values (pre-filtered to externally controllable vars) |
data |
Input data as list of reactive values |
eval |
Reactive that evaluates block expression against input data |
A ctrl_block plugin object
## Not run: serve( new_board(new_dataset_block("iris")), plugins = custom_plugins(ai_ctrl_block()) ) ## End(Not run)## Not run: serve( new_board(new_dataset_block("iris")), plugins = custom_plugins(ai_ctrl_block()) ) ## End(Not run)
Creates a backend that controls how the LLM can explore input data during block argument discovery.
data_exploration_backend(type = c("none", "manual", "tools"), ...)data_exploration_backend(type = c("none", "manual", "tools"), ...)
type |
Backend type: |
... |
Passed to backend constructor (e.g. |
A list with setup(client, data), process(response, data),
and probes_used().
S3 generic that summarises an object's structure (dimensions, column types,
sample rows, keys, etc.) as a character string suitable for inclusion in an
LLM prompt. Packages can define methods for custom types (e.g.
blockr.dm registers a dm method).
data_schema(x, ...) ## S3 method for class 'data.frame' data_schema(x, ...) ## Default S3 method: data_schema(x, ...) ## S3 method for class 'ggplot' data_schema(x, ...)data_schema(x, ...) ## S3 method for class 'data.frame' data_schema(x, ...) ## Default S3 method: data_schema(x, ...) ## S3 method for class 'ggplot' data_schema(x, ...)
x |
Object to summarise. |
... |
Additional arguments passed to methods. |
Character string.
Consider moving this generic to blockr.core so that any package can provide methods without depending on blockr.ai.
Uses an LLM to discover block arguments from a natural language prompt. The function iteratively queries the LLM, validates responses, and refines until successful or max iterations reached.
discover_block_args( prompt, block, data = NULL, validate = NULL, max_iter = 5, verbose = FALSE, client = NULL, current_state = NULL, data_exploration = blockr.core::blockr_option("data_exploration", "manual"), reporter = NULL, images = NULL )discover_block_args( prompt, block, data = NULL, validate = NULL, max_iter = 5, verbose = FALSE, client = NULL, current_state = NULL, data_exploration = blockr.core::blockr_option("data_exploration", "manual"), reporter = NULL, images = NULL )
prompt |
User prompt describing what they want (e.g., "setosa only") |
block |
A block object (e.g., |
data |
Input data (data.frame, dm, or NULL for source blocks) |
validate |
Validation function. If NULL, uses standalone validator with testServer (for testing outside of Shiny). |
max_iter |
Maximum LLM iterations (default 5) |
verbose |
If TRUE, print conversation to console |
client |
An existing ellmer chat client to reuse. When NULL (default), a new client is created. Pass a persistent client to retain conversation memory across multiple calls. |
current_state |
Optional plain list of current block parameter values. When non-NULL, a "Current Configuration" section is included in the user message so the LLM can see what's already configured. |
data_exploration |
Data exploration strategy passed to
|
reporter |
A progress reporter list (see reporter_silent, reporter_console, reporter_shiny). When NULL (default), auto-detects: console if interactive, silent otherwise. |
images |
Optional list of base64-encoded images to include with the first prompt. |
List with:
success |
TRUE if args were discovered successfully |
args |
List of discovered arguments |
result |
The resulting object: data.frame, dm, ggplot, etc. (if successful) |
error |
Error message (if failed) |
conversation |
List of message exchanges (if verbose) |
client |
The ellmer chat client (R6). Pass to subsequent calls to retain conversation memory. |
## Not run: # Filter block result <- discover_block_args( prompt = "setosa only", block = new_filter_block(), data = iris, verbose = TRUE ) result$success result$result # Dataset block (no input data) result <- discover_block_args( prompt = "use mtcars", block = new_dataset_block() ) # Conversation memory: pass result$client to follow-up calls r1 <- discover_block_args("use iris", new_dataset_block()) r2 <- discover_block_args("now mtcars", new_dataset_block(), client = r1$client) # Summarize block result <- discover_block_args( prompt = "average sepal length by species", block = new_summarize_block(), data = iris ) ## End(Not run)## Not run: # Filter block result <- discover_block_args( prompt = "setosa only", block = new_filter_block(), data = iris, verbose = TRUE ) result$success result$result # Dataset block (no input data) result <- discover_block_args( prompt = "use mtcars", block = new_dataset_block() ) # Conversation memory: pass result$client to follow-up calls r1 <- discover_block_args("use iris", new_dataset_block()) r2 <- discover_block_args("now mtcars", new_dataset_block(), client = r1$client) # Summarize block result <- discover_block_args( prompt = "average sepal length by species", block = new_summarize_block(), data = iris ) ## End(Not run)
Tools can be made available to LLMs in order to make them more powerful and in turn enabling them to create more accurate results.
new_llm_tool(..., prompt = character()) is_llm_tool(x) get_tool(x) get_prompt(x)new_llm_tool(..., prompt = character()) is_llm_tool(x) get_tool(x) get_prompt(x)
... |
Passed to |
prompt |
A string with additional prompts that will be added to the system prompt. |
x |
Object |
All blocks constructed via new_llm_tool() inherit from
llm_tool.
Prints the full conversation history from a discover_block_args() result
in a readable format.
print_conversation(x)print_conversation(x)
x |
Result from |
Invisibly returns x
## Not run: result <- discover_block_args( prompt = "setosa only", block = new_filter_block(), data = iris, verbose = TRUE ) print_conversation(result) ## End(Not run)## Not run: result <- discover_block_args( prompt = "setosa only", block = new_filter_block(), data = iris, verbose = TRUE ) print_conversation(result) ## End(Not run)
Prints formatted progress to stdout. Useful for interactive standalone discovery and debugging.
reporter_console()reporter_console()
A reporter list
Uses shinychat's chunk protocol to show live progress in the chat widget.
Opens a single streaming assistant message and shows one active badge at a
time using operation = "replace". When done() is called the message is
closed.
reporter_shiny(chat_id, session)reporter_shiny(chat_id, session)
chat_id |
The shinychat chat widget ID (namespaced) |
session |
The Shiny session |
A reporter list
No-op reporter for benchmarks and non-interactive use. All callbacks are empty functions.
reporter_silent()reporter_silent()
A reporter list