Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nomnoml Renderer #526

Merged
merged 18 commits into from Mar 28, 2024
Merged

Add Nomnoml Renderer #526

merged 18 commits into from Mar 28, 2024

Conversation

rjwignar
Copy link
Collaborator

@rjwignar rjwignar commented Mar 26, 2024

This fixes #466

Summary of Changes

This adds Nomnoml rendering support to ChatCraft using skanaar/nomnoml.

This feature was heavily based on Mermaid rendering support using mermaid-js. For example, Nomnoml rendering is handled by NomnomlPreview.tsx similar to how Mermaid rendering is handled by MermaidPreview.tsx, and similar to mermaid, the rendering is done in Markdown.tsx when a nomnoml code block is detected:

} else if (language === "mermaid") {
preview = (
<MermaidPreview children={Array.isArray(children) ? children : [children]} />
);
} else if (language === "nomnoml") {
preview = (
<NomnomlPreview children={Array.isArray(children) ? children : [children]} />
);

Differences from Mermaid rendering

Although this feature is modelled off of Mermaid rendering, due to the differences between the nomnoml and mermaid-js libraries I had to implement Nomnoml rendering differently:

No Error Message in the Nomnoml Preview

Whenever mermaidjs fails to render mermaid code, it renders an image in the preview, but
Nomnoml currently does not render an error image, so failed renders are rendered as a blank diagram instead:
image

No SVG ID value support

Unlike the mermaid-js render method, nomnoml's renderSvg method does not support an ID parameter, so in NomnomlPreview.tsx an ID value is not generated or assigned to the rendered SVG.

No config method/no way to directly modify default styling

Nomnoml currently (as of 1.6.2) does not expose a config method like mermaid.initialize.
This means there's currently no way to programatically modify the default styling of nomnoml diagrams.
However, nomnoml has directives that modify styling

Alternative Styling Modification

In the future, I see two ways users can reliably indirectly modify the styling:

  • The user can update the system prompt with instructions for nomnoml styling
  • Within a ChatCraft conversation, the user iteratively ask the LLM to modify the styling

However, both of these methods are heavily dependent on the LLM.
Even GPT-4 seems to hallucinate on nomnoml syntax when asked to modify styling, unless a directive example is provided

@rjwignar rjwignar changed the title Issue 466 Add Nomnoml Renderer Mar 26, 2024
Copy link

cloudflare-pages bot commented Mar 26, 2024

Deploying chatcraft-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 30cc7e0
Status: ✅  Deploy successful!
Preview URL: https://b7ce200b.console-overthinker-dev.pages.dev
Branch Preview URL: https://issue-466.console-overthinker-dev.pages.dev

View logs

Copy link
Collaborator

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.

We should consider an update to the default system prompt to use this.

@tarasglek
Copy link
Owner

tarasglek commented Mar 26, 2024

Lets change it
Use nomnoml or Mermaid diagrams when discussing visual topics seems to work great

@rjwignar rjwignar marked this pull request as ready for review March 26, 2024 17:29
@rjwignar
Copy link
Collaborator Author

Hi @tarasglek, @humphd, I've updated the default system prompt following your suggestions.
I've also added new changes to the PR and updated my PR summary. I'm interested to see if you have any thoughts or suggestions on my observations when making this PR.

Copy link
Collaborator

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Screenshot 2024-03-26 at 7 11 19 PM

@rjwignar rjwignar self-assigned this Mar 27, 2024
@tarasglek
Copy link
Owner

Love it!

Screenshot 2024-03-26 at 7 11 19 PM

This is fantastic diagram to use in a blog :)

@rjwignar
Copy link
Collaborator Author

rjwignar commented Mar 27, 2024

Recently updated this PR with an error message that renders in the Nomnoml preview if the nomnoml code cannot be rendered:
image

Similar to MermaidPreview, copying the preview card when there's an error will still copy the actual error:
nomnomlCopyError

Copy link
Collaborator

@WangGithub0 WangGithub0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so cool! Looks good to me!

@rjwignar rjwignar merged commit 947ff75 into main Mar 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add nomnoml renderer
4 participants