You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be really nice if there was a way to leverage the markdown output from LLM responses in Quarto documents.
For example, a code chunk in a Quarto document like:
```{r}
library(elmer)
chat <- chat_claude(
system_prompt = "You are a friendly but terse assistant. You always use markdown syntax for code.",
)
chat$chat("How can I access the first element of a vector in R?")
```
Might end up rendering to something like:
Using #| output: asis gets you part-way there but it really needs some styling to set it apart from the other body text in the document. There's not an easy way to do this from the Quarto side.
---title: "."keep-md: true---```{r}#| message: falselibrary(elmer)chat <- chat_github( system_prompt = "You are a friendly but terse assistant. You always use markdown syntax for code.",)chat$chat("How can I access the first element of a vector in R?") |> knitr:::pandoc_div("callout-note") |> knitr::asis_output()```
This is what a custom knit_print could do if the chat() output had a class it could be applied on.
@cwickham in the meantime this is also possible to create a knitr custom engine, and format output of the engine as you would like
---title: "elmer engine"keep-md: true---```{r}#| echo: falseknitr::knit_engines$set( elmer = function(options) { if (isFALSE(options$eval)) { return(knitr::engine_output(options, options$code, "")) } elmer_chatt <- options$chat if (is.character(elmer_chatt)) { elmer_chatt = get(elmer_chatt, envir = knitr::knit_global()) } if (is.null(elmer_chatt)) { stop("A chat_* object is required to use 'elmer' engine. See https://elmer.tidyverse.org/", call. = FALSE) } res <- elmer_chatt$chat(options$code) # quarto context if (!is.null(knitr::opts_knit$get('quarto.version'))) { xfun::fenced_div( attrs = ".callout-note", c( "## Reply from chat using `elmer`", "", res ) ) |> paste0(collapse = "\n") |> knitr::asis_output() } else { xfun::fenced_div( attrs = '.elmer-output', res ) |> paste0(collapse = "\n") |> knitr::asis_output() } })``````{r}#| message: falselibrary(elmer)chat <- chat_github( system_prompt = "You are a friendly but terse assistant. You always use markdown syntax for code.",)``````{elmer}#| chat: chat"How can I access the first element of a vector in R?"```
It would be really nice if there was a way to leverage the markdown output from LLM responses in Quarto documents.
For example, a code chunk in a Quarto document like:
Might end up rendering to something like:
Using
#| output: asis
gets you part-way there but it really needs some styling to set it apart from the other body text in the document. There's not an easy way to do this from the Quarto side.CC @cderv
The text was updated successfully, but these errors were encountered: