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

Support for rendering of mathematical formulas #515

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ceicke
Copy link
Contributor

@ceicke ceicke commented Oct 2, 2024

Better support the rendering of mathematical formulas.

Better support the rendering of mathematical formulas.
@ceicke
Copy link
Contributor Author

ceicke commented Oct 2, 2024

@krschacht I really don't know if this is a good way of doing this... what do you think? One test is already failing which already says a lot. Feels very hacky.

@krschacht
Copy link
Contributor

It's a good idea to add support for this! But hmm, that's tricky. The failing tests are simply because of removing html_escape() on the text that comes back. I tried adding it back and the tests pass, but then the math equation is not displayed properly—I just see a bunch of HTML.

The reason I had to add this html_escape was because sometimes the LLM will reply with actual HTML when it's explaining something to you. If this HTML is rendered by the browser rather than being escaped and displayed to the user, sometimes the text doesn't make sense. For example, you might ask "how do I make a table in HTML" and the LLM is trying to show you the HTML but the browser is rendering the HTML instead of displaying it. In addition, the LLM could return HTML that would cause the overall page layout to break. Somehow we'll have to differentiate between math and other html that the LLM may return.

Also, it's not impossible to use a JS library to do final rendering on the front-end, but I've been trying to avoid it. Parts of the page refresh a lot during streaming and I ran into some odd issues with render cycles. This is what led me to do serverside converting from markdown into HTML, using Redcarpet.

The easiest would be if Redcarpet supported some markup for math. I'm not very familiar with the options for math markup, but I did a little bit of digging and it seems like Redcarpet does not. However, in their forums they recommended a different ruby markdown parser: Kramdown. Maybe the best route to go would be to switch from Redcarpet to Kramdown and then lean into their support for math? e.g. https://kramdown.gettalong.org/documentation.html

@krschacht krschacht marked this pull request as draft November 5, 2024 16:53
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.

2 participants