feat(chat): Improve markdown handling #1777
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This PR attempts to solve the problem of wanting to use HTML intermixed in the markdown given to the streaming markdown component. This is complicated by the fact that it's common to use html-like tags to mark up parts of the prompt, so we might want to render
<img>
but have<example>
escaped to appear in the view. Currently, (when writing up this PR at least) all HTML is escaped, so it wasn't possible to add an image using HTML.Background
Initially, this PR started by allowing
content_type
on<shiny-user-chat>
to customize the content type of the user message (previously hard-coded to `"semi-markdown").I still think that's a reasonable thing to do, but I think we could simplify and have a single "markdown" mode. That said, I've kept
markdown
andsemi-markdown
for now, but I've refactored them a bit.semi-markdown
now lets more HTML through while escaping any unknown tags to retain them in the markup.We can consolidate into
markdown
,html
andtext
message modes by reverting b90c211.Example prompts
Note that if we made
markdown
andsemi-markdown
the same thing, the echoed output from this assistant would match the user message presentation.