if (FALSE) {
library(openaiRtools)
client <- OpenAI$new(api_key = "sk-xxxxxx")
# --- URL image ---
msg <- create_multimodal_message(
text = "What is shown in this chart?",
images = list("https://example.com/gdp_chart.png")
)
response <- client$chat$completions$create(messages = list(msg), model = "gpt-4o")
# --- Local file ---
msg <- create_multimodal_message(
text = "Identify any statistical issues in this residual plot.",
images = list("output/resid_plot.png"),
detail = "high"
)
# --- Multiple images (compare two charts) ---
msg <- create_multimodal_message(
text = "Compare these two regression diagnostics plots.",
images = list("plot_model1.png", "plot_model2.png"),
detail = "high"
)
# --- Mix of pre-built parts ---
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) +
geom_point()
msg <- create_multimodal_message(
text = "Describe the scatter pattern.",
images = list(image_from_plot(p, dpi = 180))
)
}
Run the code above in your browser using DataLab