open-webui
open-webui copied to clipboard
enh: configurable latex delimiters
Is your feature request related to a problem? Please describe.
OpenWebUI is able to render TeX markup when it's enclosed in double $ signs, such as $$y = f(x)$$. I did my best but failed to explain that to Llama-3. It still uses single $ once in a while.
Describe the solution you'd like
It would be nice to have a way to configure the renderer, so that single $ entries would also be treated as TeX markup. Even better if $ quotes would be automatically treated and correctly rendered as an inline markup.
Describe alternatives you've considered
- Use ChatGPT... It just works.
- Invent a prompt that would prevent a model from using single-
$styled formulas.
Additional context Sample output: https://openwebui.com/c/korvin/340ca756-a00b-4408-8acc-bc0c39fbb426
Note that some formulas are syntactically correct but not rendered properly due to single $ quotation.
It looks even worse in the UI:
Me, too. Sometimes the math doesn't work
Sometimes the math doesn't work
https://github.com/open-webui/open-webui/pull/3930 Look at this. I tried to solve this problem
why not fix it?
why not fix it?
The version is not the same, the author can pay attention to the latest dev version after the fix, and provide corresponding examples so that the author can better fix
For me it breaks in version 0.3.16 still when models are using $$ without newlines. And if it uses align or equation environments, it would break also.
If told to do newlines with $$ then it's ok
I added the following styleguide and it helped a bit:
`
### Key Guidelines for Displaying Equations in LaTeX
1. **Inline Math (`$...$`)**:
- Use for simple equations within text.
- Example: `The formula is $x = 2$.`
- **Important**: Avoid placing math expressions within brackets like `($V^\pi(s)$)`. Instead, use `\(...\)` for proper formatting:
```markdown
Incorrect: ($V^\pi(s)$)
Correct: \((V^\pi(s))\)
```
2. **Bold Text and Math**:
- Avoid placing math directly within bold syntax. Apply bold formatting only to text and NOT math.
- **Incorrect**: `**Value Function Update ($V_\theta(s)$):**`
- **Correct**: `**Value Function Update:** \(V_\theta(s)\)`
3. **Display Math (`\[...\]` or `$$...$$`)**:
- Use for equations that stand alone on their own line.
- Example:
\[
y = mx + b
\]
- Or equivalently:
$$
y = mx + b
$$
4. **Matrix Environments**:
- Use `bmatrix` or `pmatrix` within display math for matrices.
- Example:
\[
A = \begin{bmatrix}
1 & 2 \\
3 & 4
\end{bmatrix}
\]
5. **Multiline Equations**:
- Avoid `align` or `equation` environments for multiline equations. Use separate display math for each line.
- **Incorrect**:
```latex
\begin{align}
\nabla_\theta J(\pi_\theta) &= \sum_t \gamma^t r(s_t, a_t) \\
\Delta \theta &= \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a)
\end{align}
```
- **Correct**:
\[
\nabla_\theta J(\pi_\theta) = \sum_t \gamma^t r(s_t, a_t)
\]
\[
\Delta \theta = \alpha_a \nabla_\theta \log \pi_\theta(a|s) A(s,a)
\]
Same issue, the tex rendering is not working: