azure-search-openai-demo icon indicating copy to clipboard operation
azure-search-openai-demo copied to clipboard

XML/HTML responses from OpenAI Chat don't render properly

Open jrichMQ opened this issue 8 months ago • 1 comments

Example prompt "provide me a short example of xml"

Tokens come back but don't render correctly in the application, only shows part of the response.

Image

jrichMQ avatar Mar 04 '25 20:03 jrichMQ

Hm. The UI is currently designed to render Markdown, never tested with XML.

This is the relevant component that renders the response:

    const sanitizedAnswerHtml = DOMPurify.sanitize(parsedAnswer.answerHtml);

    // later:
    <div className={styles.answerText}>
        <ReactMarkdown children={sanitizedAnswerHtml} rehypePlugins={[rehypeRaw]} remarkPlugins={[remarkGfm]} />
    </div>

I think I can see the XML characters flashing by before they get removed, I am guessing that DOMPurify is removing them. You would need to change that code to see what would work well for your application. We could only make that change to the base application code if it was definitely safe, i.e. no risk of rendering unsafe HTML.

pamelafox avatar Mar 06 '25 00:03 pamelafox