# \donttest{
if (interactive()) {
# Define a weather tool
get_weather <- tool(
name = "get_weather",
description = "Get the current weather for a location",
parameters = z_object(
location = z_string(description = "The city name, e.g., 'Beijing'"),
unit = z_enum(c("celsius", "fahrenheit"), description = "Temperature unit")
),
execute = function(args) {
# In real usage, call a weather API here
paste("Weather in", args$location, "is 22 degrees", args$unit)
}
)
# Use with generate_text
result <- generate_text(
model = "openai:gpt-4o",
prompt = "What's the weather in Tokyo?",
tools = list(get_weather)
)
}
# }
Run the code above in your browser using DataLab