# \donttest{
if (interactive()) {
# Create a tool that modifies a reactive value
update_resolution_tool <- reactive_tool(
name = "update_resolution",
description = "Update the plot resolution",
parameters = z_object(
resolution = z_number() |> z_describe("New resolution value (50-500)")
),
execute = function(rv, session, resolution) {
rv$resolution <- resolution
paste0("Resolution updated to ", resolution)
}
)
# Use with aiChatServer by wrapping the execute function
server <- function(input, output, session) {
rv <- reactiveValues(resolution = 100)
# Wrap the tool to inject rv and session
wrapped_tools <- wrap_reactive_tools(
list(update_resolution_tool),
rv = rv,
session = session
)
aiChatServer("chat", model = "openai:gpt-4o", tools = wrapped_tools)
}
}
# }
Run the code above in your browser using DataLab