-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(webui): improve LaTeX rendering with currency detection #16508
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
base: master
Are you sure you want to change the base?
Conversation
|
Hey @srogmann! Thank you for this contribution :) Yeah, we will definitely work sth out from these PRs :) |
7eb8914 to
9b31191
Compare
|
@ggerganov could u also please take a look at this and test your edge cases? @watamario15 @squik67 also some feedback & testing from you would be really useful :) |
|
Okay, thanks for reporting @ggerganov. I'd like to wait just a bit longer for @watamario15 and @squik67 to add their feedback and verify if there are more edge cases to be addressed before we introduce any further improvements to this. |
|
Thanks for the tests! I can reproduce the non-rendered formulas. The Example: working and non-working. I'll have a look at it. |
|
From my quick check, this doesn't get rendered: |
|
It's working well on my end with these ↑ commits. Thanks! (I found a small issue where GPT-OSS tends to escape |
|
Oh, it looks like erroring on \[
\boxed{
\begin{aligned}
N_{\text{att}}^{\text{(MHA)}} &=
h \bigl[\, d_{\text{model}}\;d_{k} + d_{\text{model}}\;d_{v}\, \bigr] && (\text{Q,K,V の重み})\\
&\quad+ h(d_{k}+d_{k}+d_{v}) && (\text{バイアス Q,K,V)}\\[4pt]
&\quad+ (h d_{v})\, d_{\text{model}} && (\text{出力射影 }W^{O})\\
&\quad+ d_{\text{model}} && (\text{バイアス }b^{O})
\end{aligned}}
\] |
|
@watamario15 Thanks! The rendering is now better, but the spacers (e.g. |
|
I went ahead and merged #16599 first because it was a quick fix for the immediate issue in #16598 – just converting On the other hand your PR solves a bigger problem that #16599 doesn't touch – distinguishing money from math. Right now, Since your Let me know your thoughts! |
|
@allozaur The quick fix in #16599 helps in a lot of cases. I wil rebase. Your samples in |
6f8bc9c to
688392e
Compare
|
Regarding the spacer example from @watamario15, I added a small fix and unit test. A sub-pattern like |
In real-world scenarios, models can emit mathematical expressions in both MathJax/Markdown and pure LaTeX styles. You should never have to deal with doubled backslashes The developer option “Show raw LLM output” displays the model’s raw output directly, without any Markdown rendering or frontend parsing, for streaming mode :
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, very good improvements, just needs small polishing up before we merge it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srogmann that's a really comprehensive set of tests! supreme work 🤌
|
Rendering looks perfect on my end. BTW, I see a bunch of 404 logs, is this normal? |
Hmmm... this might be older assets cached by browser not being there. Just to make sure, please clear browsing data and recheck. |
|
I'm on |
@srogmann could u please take a look at that? |
|
You should never have to deal with doubled backslashes \( or \[ in the WebUI Have a look at the example of @watamario15: |
Code maintenance (variable names, code formatting, string handling) Co-authored-by: Aleksander Grygier <[email protected]>
|
@watamario15 I can also reproduce these 404 errors. |
|
@allozaur Regarding the 404 errors: I inserted in In vite.config.ts I added a replacement of the URLs by base64-encoded data. Since I'm not deeply familiar with Svelte or Vite, please review the changes to ensure they are correct. I am sure that there is a better way to set $use-ttf to false ;-). This will increase the size of index.html.gz, but it ensures that llama.cpp remains local (no CDN dependency). |
Hey @srogmann, thanks for that! I will take a look at this and come back to you ;) we're very close to getting this PR merged 🤞 |
|
@allozaur Update: I just noticed, that KaTeX_Size3 is already embedded, but only KaTeX_Size3. Therefore, should be no need to modify the font URLs in a way that would be hard to maintain. |
|
Update: I was wondering why KaTeX_Size3 was embedded but no other font. The answer is "< 4096" ;-). https://vite.dev/config/build-options.html#build-assetsinlinelimit: Default: 4096 (4 KiB) |
|
At |




Close #16136
This PR handles LaTeX blocks in (...) and [...], as well as dollar amounts like $100 that should not be interpreted as inline LaTeX.
Examples (e.g. prompt "Think of a grade 4 math question regarding amounts."):
[
\left{ \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}, \begin{pmatrix} -1 & 0 \ 0 & -1 \end{pmatrix} \right} = {\pm I}
]
@allozaur : I wrote most of this PR a week ago, only just now noticed issue #16136 and your PR #16496. In math-formulas.ts, I've added examples for Storybook, along with tests for Vitest. Feel free to take a look and let me know your thoughts. Detecting inline LaTeX is inherently tricky, so my approach likely won't cover every edge case, but I hope it's a step in the right direction.