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

Mangling of code in response and prompt display (and copying out) #51

Open
cmp-nct opened this issue Apr 2, 2023 · 6 comments
Open
Labels
bug Something isn't working

Comments

@cmp-nct
Copy link

cmp-nct commented Apr 2, 2023

Latest dev version:
Input: cache.buf.resize(2un_elementsggml_type_size(wtype) + 2uMB);
Output: cache.buf.resize(2un_elementsggml_type_size(wtype) + 2u
MB);

This happens with the prompt as well as when Bing answers, I'm quite sure the answer contains the correct code but the multiplications are removed.
Only when displayed in a "code box" it's working.

It's not just a visual bug, also when copy/paste the multiplications are gone.
So something is removing characters.

@cmp-nct cmp-nct added the bug Something isn't working label Apr 2, 2023
@waylaidwanderer
Copy link
Owner

waylaidwanderer commented Apr 2, 2023

That's caused by converting markdown to HTML. I think both Bing and ChatGPT would have the same behavior.

Asking it to put the code in a markdown code block instead is the correct solution to this issue.

@waylaidwanderer
Copy link
Owner

You can see it's even broken in your reply above as well ;)

@cmp-nct
Copy link
Author

cmp-nct commented Apr 2, 2023

lol, ok I'm not familiar with Markdown. I can see it was mangled here too.

Though even my input is mangled, so the prompt looks bad (I suppose Bing receives it correctly). So the display would also be partly wrong if bing puts it in a code box. In my cases Bing did create code boxes, just not about everything. So some parts were outside (and damaged).

Maybe a developer view would be the solution which removes all formating ?
I'd prefer to see all in clear text than having such errors in as it can introduce nasty bugs in code.
Or just remove the italic view as a middle approach, I'm not sure if more code/formula-breaking chars exist.
the multiplication sign is quite essential in a lot of questions and answers

@waylaidwanderer
Copy link
Owner

@cmp-nct you just gave me an idea to add a button that toggles between the "raw" response and the rendered response. Then you'd be able to copy it correctly. Would that work?

@cmp-nct
Copy link
Author

cmp-nct commented Apr 2, 2023

@cmp-nct you just gave me an idea to add a button that toggles between the "raw" response and the rendered response. Then you'd be able to copy it correctly. Would that work?

Sounds like a great feature, yes.
Though the raw view should be permanent if switched, so when in raw you can still communicate and don't need to switch back after every prompt.

I guess disabling italic wouldn't solve it as underscores are also affected. It would be nice if we had a "middle ground" that disables the majority of formating but still allows stuff like code boxes or smileys to be displayed.
For now, a raw view will at least be a quick solution to make it useable (for code).

@cmp-nct
Copy link
Author

cmp-nct commented Apr 3, 2023

I've been testing a bit but I have no knowledge of the framework you use, a bit stuck.
The below code is just 2 changed lines to process incoming messages with an escape, it also recognizes code-boxes and skips the processing inside them.
The code works while the agent is responding (during stream) all looks good, code inside code boxes looks good and the formating outside the code boxes also is skipped for underscore and for multiplication.
However, once the bot stops something reprocesses the content and strangely the text inside code boxes suddenly receives a backslash escaping. The stuff outisde codeboxes stays properly "escaped".

Maybe I'm at a dead end here with the approach and your raw view idea is the only proper solution without changing the parser to entirely ignore those characters.

In chat.vue:

const escapeMarkdownSymbols = (text) => {
  // split the text by the ``` delimiter
  const parts = text.split('```');
  // loop through the parts
  for (let i = 0; i < parts.length; i++) {
    // escape the symbols only in the odd-numbered parts
    if (i % 2 === 1) {
      parts[i] = parts[i].replace(/[\_\*]/g, '\\$&');
    }
  }
  // join the parts back together
  return parts.join('```');
};

at const handleMessageResult:

      let adaptiveText = result.details.adaptiveCards?.[0]?.body?.[0]?.text?.trim();
        if (adaptiveText) {
			adaptiveText = escapeMarkdownSymbols(adaptiveText);
            console.debug('adaptiveText', adaptiveText);
            messages.value[botMessageIndex].text = adaptiveText;
        } else {
            messages.value[botMessageIndex].text = escapeMarkdownSymbols(result.response);

It escapes those two characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants