ChatGPT-Next-Web icon indicating copy to clipboard operation
ChatGPT-Next-Web copied to clipboard

[Bug] LaTeX Syntax still bug

Open H0llyW00dzZ opened this issue 9 months ago • 36 comments

Describe the bug this symbol "\frac{1}{2}$." and this one "$a$, $b$, and $c$"

image

Logs chat : Einstein's mass-energy equivalence equation.md

H0llyW00dzZ avatar Nov 12 '23 13:11 H0llyW00dzZ

this one aswell

  • $$2x^2 - 5x + 2 = 0$$
  • $2x^2 - 5x + 2 = 0$ are $x = 2$ and $x = \frac{1}{2}$.

image

H0llyW00dzZ avatar Nov 12 '23 14:11 H0llyW00dzZ

I found that it worked fine after add a space after the left "$"

VergilWang15 avatar Nov 20 '23 15:11 VergilWang15

I found that it worked fine after add a space after the left "$"

need changed in this https://github.com/Yidadaa/ChatGPT-Next-Web/blob/f2485931d9b3680234f4816f4526759c8d4b741e/app/components/markdown.tsx#L102

function escapeDollarNumber(text: string) {
  let escapedText = "";

  for (let i = 0; i < text.length; i += 1) {
    let char = text[i];
    const nextChar = text[i + 1] || " ";

    if (char === "$" && nextChar >= "0" && nextChar <= "9") {
      char = "\\$";
    }

    escapedText += char;
  }

  return escapedText;
}

H0llyW00dzZ avatar Nov 20 '23 15:11 H0llyW00dzZ

image

it fixed by adding space bar in char = "\ \$"; before is char = "\\$";

H0llyW00dzZ avatar Nov 20 '23 16:11 H0llyW00dzZ

It makes sense, I think the author add this function to avoid some sentense being misunderstood, like

I got $2 for a hotdog and $1 for a cup of tea.

But it also bring another issue here

VergilWang15 avatar Nov 20 '23 16:11 VergilWang15

It makes sense, I think the author add this function to avoid some sentense being misunderstood, like

I got $2 for a hotdog and $1 for a cup of tea.

But it also bring another issue here

yeah you right if adding space bar in char = "\ \$"; before is char = "\\$"; it bring another issue about I got $2 for a hotdog and $1 for a cup of tea.

H0llyW00dzZ avatar Nov 20 '23 16:11 H0llyW00dzZ

I believe we can simply remove the function here, as in my opinion, there are numerous cases where numbers are followed by a dollar sign in mathematical expressions, which would cause a lot of confusion. Additionally, the alternative scenario is probably rare.

Furthermore, adding a method to determine whether the dollar sign here represents currency or a mathematical expression is likely to be very costly.

VergilWang15 avatar Nov 20 '23 16:11 VergilWang15

I believe we can simply remove the function here, as in my opinion, there are numerous cases where numbers are followed by a dollar sign in mathematical expressions, which would cause a lot of confusion. Additionally, the alternative scenario is probably rare.

Furthermore, adding a method to determine whether the dollar sign here represents currency or a mathematical expression is likely to be very costly.

must made another function only for math I guess for fix a lot of confusion

H0llyW00dzZ avatar Nov 20 '23 16:11 H0llyW00dzZ

I believe we can simply remove the function here, as in my opinion, there are numerous cases where numbers are followed by a dollar sign in mathematical expressions, which would cause a lot of confusion. Additionally, the alternative scenario is probably rare. Furthermore, adding a method to determine whether the dollar sign here represents currency or a mathematical expression is likely to be very costly.

must made another function only for math I guess for fix a lot of confusion

The main issue is that we seem unable to automatically differentiate whether the text returned by GPT is a LaTeX expression or a currency symbol.

I'm wondering if we can address this problem through prompt engineering by asking GPT to actively add escape characters for these currency symbol, for example:

The price of pineapple fried rice is \$5, which is \$1 cheaper than before.

VergilWang15 avatar Nov 20 '23 16:11 VergilWang15

I believe we can simply remove the function here, as in my opinion, there are numerous cases where numbers are followed by a dollar sign in mathematical expressions, which would cause a lot of confusion. Additionally, the alternative scenario is probably rare. Furthermore, adding a method to determine whether the dollar sign here represents currency or a mathematical expression is likely to be very costly.

must made another function only for math I guess for fix a lot of confusion

The main issue is that we seem unable to automatically differentiate whether the text returned by GPT is a LaTeX expression or a currency symbol.

I'm wondering if we can address this problem through prompt engineering by asking GPT to actively add escape characters for these currency symbol, for example:

The price of pineapple fried rice is \$5, which is \$1 cheaper than before.

the text returned by GPT is $3x^2 + 6x - 9 = 0$ mostly (e.g when you entering "$$ 3x^2 + 6x - 9 = 0 $$")

Screenshot_372

logs :

Quadratic Equation: Solving for x

Message From ChatGPT:

You are an assistant that Quadratic Equation: Solving for x

Message From You:

$$ 3x^2 + 6x - 9 = 0 $$

Message From ChatGPT:

To solve the quadratic equation $3x^2 + 6x - 9 = 0$, we can use the quadratic formula. The quadratic formula states that for an equation in the form $ax^2 + bx + c = 0$, the solutions for $x$ can be found using the formula:

$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

In our equation, $a = 3$, $b = 6$, and $c = -9$. Substituting these values into the quadratic formula, we get:

$$x = \frac{-6 \pm \sqrt{6^2 - 4(3)(-9)}}{2(3)}$$

Simplifying further:

$$x = \frac{-6 \pm \sqrt{36 + 108}}{6}$$ $$x = \frac{-6 \pm \sqrt{144}}{6}$$ $$x = \frac{-6 \pm 12}{6}$$

This gives us two possible solutions for $x$:

$$x_1 = \frac{-6 + 12}{6} = \frac{6}{6} = 1$$ $$x_2 = \frac{-6 - 12}{6} = \frac{-18}{6} = -3$$

Therefore, the solutions to the equation $3x^2 + 6x - 9 = 0$ are $x = 1$ and $x = -3$.

H0llyW00dzZ avatar Nov 20 '23 17:11 H0llyW00dzZ

also we can't tell gpt to show output format in prompt because it's weird, its better depends what gpt said

so the main problem its only that how we can escaping $$ without conflict of single $ for Math/Latex

H0llyW00dzZ avatar Nov 20 '23 17:11 H0llyW00dzZ

another issue :

image

this a $ "$3 \times 10^8$" should be "$ 3 \times 10^8$" if "$ 3 \times 10^8$" it will show output correctly

$ 3 \times 10^8$

Screenshot_373

H0llyW00dzZ avatar Nov 20 '23 17:11 H0llyW00dzZ

info update

looks better

using this code :

// used to be for math / latex
function escapeDollarNumber(text: string) {
  let escapedText = "";

  for (let i = 0; i < text.length; i += 1) {
    let char = text[i];
    const nextChar = text[i + 1] || " ";

    if (char === "$" && nextChar >= "\\" + "0" + "\\" && nextChar <= "\\" + "9" + "\\") {
      char = "\\$";
    }

    escapedText += char;
  }

  return escapedText;
}
// used to be $ any still wip
function escapeDollarMathNumber(text: string) {
  let escapedText = "";
  let isInMathExpression = false;

  for (let i = 0; i < text.length; i += 1) {
    let char = text[i];
    const nextChar = text[i + 1] || " ";

    if (char === "$") {
      isInMathExpression = !isInMathExpression;
    }

    if (char === "$" && nextChar >= "0" && nextChar <= "9" && !isInMathExpression) {
      char = " " + nextChar;
    }

    escapedText += char;
  }

  return escapedText;
}

function _MarkDownContent(props: { content: string }) {
  const escapedContent = useMemo(() => {
    let processedContent = props.content;
    if (processedContent.includes("$")) {
      processedContent = escapeDollarMathNumber(processedContent);
    }
    processedContent = escapeDollarNumber(processedContent);
    return processedContent;
  }, [props.content]);

image

output json :

image

image

only single dollar now a issue

H0llyW00dzZ avatar Nov 20 '23 20:11 H0llyW00dzZ

@VergilWang15 issue should be fixed for sure (I am smart)

testing on azure by asking "can you solving this $3x^2 + 6x - 9 = 0$ ?"

image

output json :

image

code :

// used to be for math / latex
function escapeDollarNumber(text: string) {
  let escapedText = "";

  for (let i = 0; i < text.length; i += 1) {
    let char = text[i];
    const nextChar = text[i + 1] || " ";

    if (char === "$" && nextChar >= "\\" + "0" + "\\" && nextChar <= "\\" + "9" + "\\") {
      char = "\\$";
    }

    escapedText += char;
  }

  return escapedText;
}
// used to be $ any
function escapeDollarMathNumber(text: string) {
  let escapedText = "";
  let isInMathExpression = false;

  for (let i = 0; i < text.length; i += 1) {
    let char = text[i];
    const nextChar = text[i + 1] || " ";

    if (char === "$") {
      isInMathExpression = !isInMathExpression;
    }

    if (char === "$" && nextChar >= "0" && nextChar <= "9" && !isInMathExpression) {
      char = "&#36;" + nextChar; // "&#36;" <--- this magic
      i += 1; // Skip the next character since we have already included it
    }

    escapedText += char;
  }

  return escapedText;
}

function _MarkDownContent(props: { content: string }) {
  const escapedContent = useMemo(() => {
    let processedContent = props.content;
    if (processedContent.includes("$")) {
      processedContent = escapeDollarMathNumber(processedContent);
    }
    processedContent = escapeDollarNumber(processedContent);
    return processedContent;
  }, [props.content]);

Another Highlight:

  • Azure

Quadratic and Cubic Equation Solutions

  • OpenAI

image

H0llyW00dzZ avatar Nov 20 '23 21:11 H0llyW00dzZ

another highligh gpt-4-1106-preview :

image

LaTeX Mathematical Formulae Overview

H0llyW00dzZ avatar Nov 20 '23 23:11 H0llyW00dzZ

@VergilWang15 it won't conflict now

image

BetaTesting : https://github.com/H0llyW00dzZ/ChatGPT-Next-Web/commit/236f9fc2e7ca33400b55389ffa9a5c0d67d561aa

Models : gpt-4-1106-preview

H0llyW00dzZ avatar Nov 23 '23 16:11 H0llyW00dzZ

looks nice!

VergilWang15 avatar Nov 24 '23 01:11 VergilWang15

looks nice!

list model recommended & not recommended for LaTex Syntax https://github.com/Yidadaa/ChatGPT-Next-Web/discussions/3351

H0llyW00dzZ avatar Nov 24 '23 01:11 H0llyW00dzZ

I also have the same problem, not even with the latest version 2.10.1 the issue has been resolved.

boromyr avatar Dec 28 '23 22:12 boromyr

By the way, can NextChat modify the listening address and port?

daiaji avatar Feb 27 '24 07:02 daiaji

By the way, can NextChat modify the listening address and port?

you mean ip address and port ?

H0llyW00dzZ avatar Feb 27 '24 08:02 H0llyW00dzZ

you mean ip address and port ?

yes

daiaji avatar Feb 27 '24 08:02 daiaji

you mean ip address and port ?

yes

Currently, it doesn't support ip address and port. You need to forward it to a domain such as localhost or use a service like https://ngrok.com/.

H0llyW00dzZ avatar Feb 27 '24 08:02 H0llyW00dzZ

Can this feature be supported? Basically, when I deploy in pod, I can directly use the localhost:3000 reverse proxy for NextWeb, but one-api also uses port number 3000, which causes conflicts, and it is indeed strange that the listening address and port cannot be modified.

daiaji avatar Feb 27 '24 09:02 daiaji

Can this feature be supported? Basically, when I deploy in pod, I can directly use the localhost:3000 reverse proxy for NextWeb, but one-api also uses port number 3000, which causes conflicts, and it is indeed strange that the listening address and port cannot be modified.

You can change the port by rebuilding the application, for instance, in Docker.

H0llyW00dzZ avatar Feb 27 '24 09:02 H0llyW00dzZ

this one you need to changed it

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/Dockerfile#L43C1-L44C1

H0llyW00dzZ avatar Feb 27 '24 09:02 H0llyW00dzZ

this one you need to changed it

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/Dockerfile#L43C1-L44C1

This appears to be just docker's port mapping.

daiaji avatar Feb 27 '24 09:02 daiaji

this one you need to changed it https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/Dockerfile#L43C1-L44C1

This appears to be just docker's port mapping.

https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/docker-compose.yml

H0llyW00dzZ avatar Feb 27 '24 09:02 H0llyW00dzZ

or use docker desktop it much easier to fix conflict ports example:

image

H0llyW00dzZ avatar Feb 27 '24 09:02 H0llyW00dzZ

Bot detected the issue body's language is not English, translate it automatically.


or use docker desktop it much easier to fix conflict ports example:

image

Issues-translate-bot avatar Feb 27 '24 09:02 Issues-translate-bot