-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[v0.9.1] Formatting issues while rendering code #1337
Comments
OK. Think I can explain this one, and offer an improvement. Code blocks in markdown can either be fenced ( The issue arises when the LLM responds with a code block that is both fenced AND indented. In this case I think the correct behaviour is to show a code block, with the fences displayed as part of the code. VSCode and https://markdownlivepreview.com/ do this. What is happening in Chat-UI seems to be:
In looking at this, I've bumped the marked library to 13.0.3 and then 14.0 (to see if this fix : markedjs/marked#3264 would make a difference - it doesn't). This does change the interface a little but fairly easy to update. In the meantime, adding this to ChatMessage returns the
@nsarrazin - let me know if you want this as a PR - I think this improves behaviour but isn't a proper fix. In the meantime, I'm going to tweak my System prompt to advise the LLM against using indents for Code Blocks, and ultimately think this is a defect in the marked library? |
Leaving the previous comment, however I am not 100% confident on whether indents are the only cause after more testing. The output below uses
|
Here is a snippet that shows the issue: The handling of code blocks in lists changes; asking the LLM via Chat-UI to repeat all or part of the block verbatim shows the behaviour. The GFM spec recommends using a blank HTML comment to disambiguate indented blocks: https://github.github.com/gfm/#example-288
Outside a ListThis is a test (normal fences) <foo /> This is another test (indented block)
This is another test (indents and fences)
Test complete
|
Final update on this for the moment - the issue also occurs when code blocks are children of lists, causing the parse(token.raw) to show the child codeblock rather than being caught by the type==="code" clause here: chat-ui/src/lib/components/chat/ChatMessage.svelte Lines 267 to 276 in 97b6feb
Can't see an obvious quick way to fix this. |
Getting this issue with Qwen2.5-Coder-32B-Instruct: The raw markdown looks like: ### Explanation of the Code
1. **Loop through each `char*` and delete it:**
```cpp
for (size_t i = 0; i < count; i++) {
delete suggestions[i];
suggestions[i] = 0;
} Seems like the code block produced by Qwen is indented, which usually isn't common, but seems to be more common with this particular model. |
It's because it's a child of a bulleted/numbered list. In this case it
doesn't use the CodeBlock component but the marked output.
…On Tue, 12 Nov 2024, 09:19 Rotem Dan, ***@***.***> wrote:
Getting this issue with Qwen2.5-Coder-32B-Instruct:
Screenshot_1.png (view on web)
<https://github.com/user-attachments/assets/bcac2c50-e676-4a2c-9393-1a6aa60dffb1>
The raw markdown looks like:
### Explanation of the Code
1. **Loop through each `char*` and delete it:**
```cpp
for (size_t i = 0; i < count; i++) {
delete suggestions[i];
suggestions[i] = 0;
}
Seems like the code block produced by Qwen is indented, which usually
isn't common, but seems to be more common with this particular model.
—
Reply to this email directly, view it on GitHub
<#1337 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOYXFQ6HIS3NX7Q73VCHWD2AHBZXAVCNFSM6AAAAABKVHNUMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRZHE4TKOBYGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Last reply not helpful - there are 2 separate issues:
I can produce a PR for the second issue (I fixed this in my fork but left it as it's not a "complete" fix). Adding this to ChatMessage fixes the <'s.
|
@nsarrazin Whenever I ask chat-ui to explain / generate code, the
<
does not get rendered correctly. Can you please take a look?The text was updated successfully, but these errors were encountered: