if (FALSE) {
library(openaiRtools)
library(ggplot2)
client <- OpenAI$new(api_key = "sk-xxxxxx")
# Build a ggplot2 chart
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point() +
geom_smooth(method = "lm") +
labs(title = "Car Weight vs Fuel Efficiency", x = "Weight", y = "MPG")
# Send plot directly to GPT-4o
response <- client$chat$completions$create(
messages = list(
list(
role = "user",
content = list(
list(
type = "text",
text = "Describe the relationship shown in this scatter plot."
),
image_from_plot(p, dpi = 150)
)
)
),
model = "gpt-4o"
)
cat(response$choices[[1]]$message$content)
}
Run the code above in your browser using DataLab