
Diagrams
It is often useful to request an LLM to generate a diagram. Fortunately, many LLMs already know mermaid, a popular Markdown extension to create diagrams and charts.
Automatic Mermaid syntax repair
Section titled “Automatic Mermaid syntax repair”The system.diagrams
system prompt registers a repair chat participant that will try to fix any syntax errors in the generated Mermaid diagrams. It’s not uncommon for LLMs to generate invalid Mermaid syntax, so this is a useful feature.
Parser
Section titled “Parser”You can invoke the mermaid parser directly
from GenAIScript using the parsers.mermaid
function.
You can use the result.error
value to check if the parsing was successful. If it was not, you can use the result.error
value to repair the diagram with an LLM.
Markdown Preview support
Section titled “Markdown Preview support”-
Install the Markdown Preview Mermaid Support extension for VS Code.
-
Mention
diagram
in the program or addsystem.diagram
to the system prompt list.
$`Generate a diagram of a merge.`
👤 user
Generate a diagram of a merge.
🤖 assistant
```mermaidgraph LR A[Master] --> B((Merge Point)) C[Feature Branch] --> B```
The generated Markdown will appear as follows:
```mermaidgraph LR A[Master] --> C[New Commit] B[Feature Branch] --> C```
and it gets rendered automatically once you install the extension.