Is there a way to stream the response from chatGPT and style the markdown?
I did see this post, Any simple MarkDown Viewer?, and I tried to implement something similar, but I couldn’t figure out how to handle the streaming correctly.
It seems like a Javascript component might be the way to go, but I’ve never done that from Flow.
It’s funny, with so many AI project examples out there, you’d think this would have been solved already. I did look at Marcus’ docs-assistant, but that’s a Hilla app.
Maybe a workaround is that I stream the text, then, after it’s done, go back and style it.
@Matti has a handy MarkdownMessage in his addon. If that isn’t exactly what you’re looking for, you can probably at least look at how he implemented it.
The addition I needed to make to the original component was to get the streamed Markdown back (for chat history to work), but that is included in the library already.
It is not blocking the UI, but good that you mentioned… streaming only makes sense if you have enable websockets using @Push annotation in your application class.
I’m streaming from open AI no problem. as the response comes in, I simply update the UI thread accordingly. observer pattern. And we can style it on the fly by adding everything as inner html. Maybe I don’t understand the question fully.
I hope you’re aware of the security implications of adding external content as inner html? I’d strongly recommend passing all incoming content through e.g. JSoup or OWASP HTML Sanitizer first.