posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.32k stars 81 forks source link

feat(chat): Improve markdown handling #1777

Open gadenbuie opened 5 days ago

gadenbuie commented 5 days ago

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 and semi-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 and text message modes by reverting b90c2114de2d15ce6922030317d93e2b40663d04.

Example prompts

<img src="https://placehold.co/200x200"> ![](https://placehold.co/200x200) <example>thing</example>
Before After
image image

Note that if we made markdown and semi-markdown the same thing, the echoed output from this assistant would match the user message presentation.

You’re a financial analyst at **AcmeCorp**. Generate a Q2 financial report for our investors.

This is an 'unusual' character: "&amp;".

Use this data for your report:<data>{{SPREADSHEET_DATA}}</data>

<instructions>
1. Include sections: Revenue Growth, Profit Margins, Cash Flow.
2. Highlight strengths and areas for improvement.
</instructions>

Make your tone concise and professional. Follow this structure:
<formatting_example>{{Q1_REPORT}}</formatting_example>
Before After
image image