-
-
Save jimbrig/23e23df465f6344a6a13bb8f86909b32 to your computer and use it in GitHub Desktop.
Generate a Mermaid.js diagram using LLM with elmer package to explain code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(elmer) | |
library(tidyverse) | |
library(DiagrammeR) | |
library(glue) | |
code <- "starwars %>% | |
group_by(species) %>% | |
summarise( | |
n = n(), | |
mass = mean(mass, na.rm = TRUE) | |
) %>% | |
filter( | |
n > 1, | |
mass > 50 | |
)" | |
chat <- chat_openai( | |
model = "gpt-4o", | |
system_prompt = "You are a friendly but terse assistant.", | |
echo = TRUE, | |
api_args = list(temperature = 0) | |
) | |
response <- chat$chat(glue("Generate mermaid.js code explaining this R code: | |
{code}")) | |
mermaid_code <- str_extract(response, "(?s)(?<=```mermaid\\n).*?(?=```)") | |
DiagrammeR(mermaid_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment