frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Preventing Flash of Incomplete Markdown when streaming AI responses

https://engineering.streak.com/p/preventing-unstyled-markdown-streaming-ai
32•biot•1d ago

Comments

sim7c00•1d ago
fun read, its weird interacting with chatgpt around markdown sometimes.

it formats its own stuff with markdown, so if i ask it for markdown but dont explicitly specify a downloadable file, it will produce valid markdown up to where it conflicts with its own markdown, and then it gets choppy and chunked.

its an issue of my prompting is what im sure some customer service rep would be told to tell me :p because theres money to be made in courses for prompting skills perhaps, idk. (cynical view).

sure is enjoyable to struggle together with the AI to format its responses correctly :'D

porridgeraisin•1d ago
You can ask for it to put the markdown in a codeblock. It works well for me. It also works with latex.
kherud•1d ago
Is there a general solution to this problem? I assume you can only start buffering tokens once you see a construct, for which there are continuations, that once completed, would lead to the previous text being rendered differently. Of course you don't want to keep buffering for too long, since this would defeat the purpose of streaming. And you never know if the potential construct will actually be generated. Also, the solution probably has to be more context sensitive. For example, within code blocks, you'll never want to render links for []() constructs.

EDIT: One library I found is https://github.com/thetarnav/streaming-markdown which seems to combine incremental parsing with optimistic rendering, which works good enough in practice, I guess.

biot•1d ago
There are a few things in our implementation that make a more general solution unnecessary. We only need the output to support a limited set of markdown which is typically text, bullet points, and links. So we don't need code blocks (yet).

However, the second thing (not mentioned in the post) is that we are not rendering the markdown to HTML on the server, so []() markdown is sent to the client as []() markdown, not converted into <a href=...>. So even if a []() type link exists in a code block, that text will still be sent to the client as []() text, only sent in a single chunk and perhaps with the link URL replaced. The client has its own library to render the markdown to HTML in React.

Also, the answers are typically short so even if OpenAI outputs some malformed markdown links, worst case is that we end up buffering more than we need to and the user experiences a pause after which the entire response is visible at once (the last step is to flush any buffered text to the client).

kristopolous•1d ago
This exact problem is why I wrote Streamdown https://github.com/day50-dev/Streamdown

Almost every model has a slight but meaningfully different opinion on what markdown is and how creative they can be with it.

Doing it well is a non-trivial problem.

munch117•21h ago
Generating simple HTML instead of markdown would have been a solution. But I guess that ship has sailed.
graboy•18h ago
Yes. You can define a regex matching what you want, and every regex can be compiled into a state machine (https://en.wikipedia.org/wiki/Nondeterministic_finite_automa...). Then at each character you make a step in your state machine. You pause the output while the regex is not matching.
woah•1d ago
Could this result in edge cases with [ where due to some misformatting or intentional syntax that looks like the start of a markdown link, the entire response is hidden from the user?

(This comment when subjected to this processing could look like: "Could this result in edge cases with ")

biot•1d ago
If you buffer starting with the ( character, then you'd still send the [text] part of the link, and worst case is that with no matching ) character to close the link, you end up buffering the remainder of the response. Even still, the last step is "flush any buffered text to the client", so the remainder of the response will be transmitted eventually in a single chunk.

There are some easy wins that could improve this further: line endings within links are generally not valid markdown, so if the code ever sees \n then just flush buffered text to the client and reset the state to TEXT.

impure•1d ago
I do something like this too because links in emails are insanely long. It's worse in marketing emails. So I shorten the links to save on tokens and expand them again when I get the response back from the LLM.

Benchmarking Is Hard Sometimes

https://vondra.me/posts/benchmarking-is-hard-sometimes/
1•biehl•10s ago•0 comments

Passkey Deployment Checklist

https://web.dev/articles/passkey-checklist
1•vdelitz•1m ago•0 comments

Save Millions on Your Cloud Bill: 11 Strategies for Kubernetes Cost Optimization

https://blog.cleancompute.net/p/kubernetes-cost-optimization
2•nibir•3m ago•0 comments

Show HN: TypeBridge – Compile-time RPC for client/server

https://github.com/uptownhr/TypeBridge
1•uptownhr•6m ago•0 comments

Tackling performance issues caused by load from bots

https://progress.opensuse.org/news/125
3•fionera•7m ago•0 comments

Show HN: Bulktopus – Generate All Your Ad and Social Media Images 10x Faster

https://www.bulktopus.com/
1•fer_momento•8m ago•0 comments

Contrastive Flow Matching

https://arxiv.org/abs/2506.05350
1•badmonster•11m ago•1 comments

Show HN: Posture Correction Using AirPods Motion Sensors

https://github.com/wizenheimer/workwell
2•tinylm•11m ago•0 comments

Show HN: Restore Per-App Keyboard Input Language on macOS

https://gitlab.com/spacest/InputLanguageKeeper
1•rado•13m ago•0 comments

Twilio – Intentionally Clever or Accidentally Genius?

https://ramansharma.substack.com/p/twilio-intentionally-clever-or-accidentally
1•intrepidsoldier•14m ago•0 comments

Russian billionaire: SAP replacement is expensive but essential

https://energynews.oedigital.com/energy-markets/2025/06/03/russian-billionaire-sap-replacement-is-expensive-but-essential
1•teleforce•15m ago•0 comments

Ruby Newsletter 472

https://ruby.libhunt.com/newsletter/472
1•amalinovic•15m ago•0 comments

We Built Cline to Never Hold You Hostage

https://cline.bot/blog/why-we-built-cline-to-never-hold-you-hostage
3•howtofly•17m ago•0 comments

Photoshop Arrives on Android

https://blog.adobe.com/en/publish/2025/06/03/photoshop-arrives-on-android
1•teleforce•18m ago•0 comments

Musk tweets that Trump is named in Epstein files

https://www.cnn.com/2025/06/06/politics/trump-musk-epstein-files-accusation
2•strogonoff•20m ago•0 comments

Silicon Valley Is Starting to Pick Sides in Musk and Trump's Breakup

https://www.wired.com/story/musk-trump-feud-venture-capitalists-pick-sides/
2•beardyw•22m ago•0 comments

Maker of 'Most Complex Machine Humans Ever Created' Is Navigating Trade Fights

https://www.nytimes.com/2025/06/05/technology/asml-chips-tariffs-trade.html
1•doener•26m ago•0 comments

This is Water by David Foster Wallace (Full Transcript and Audio)

https://fs.blog/david-foster-wallace-this-is-water/
1•rendx•32m ago•0 comments

Obsidian 1.9.2 brings breaking changes

https://www.neowin.net/news/obsidian-192-brings-breaking-changes-ui-improvements-and-several-bug-fixes/
1•bundie•32m ago•0 comments

People Keep Inventing Prolly Trees

https://www.dolthub.com/blog/2025-06-03-people-keep-inventing-prolly-trees/
2•thunderbong•33m ago•0 comments

Tesla share plunge amid Trump feud wipes $152B off Elon Musk's company

https://www.theguardian.com/technology/2025/jun/05/tesla-share-drop-trump-musk-feud
1•beardyw•37m ago•0 comments

Australian Navy ship accidentally blocks WiFi across parts of New Zealand

https://www.theguardian.com/australia-news/2025/jun/06/australian-navy-ship-accidentally-blocks-wifi-across-parts-of-new-zealand
1•defrost•44m ago•0 comments

OpenBSD Hackathon Japan 2025

https://rsadowski.de/posts/2025/j2k25-japan-openbsd-hackathon/
1•damir•44m ago•0 comments

MLX-based LLM inference engine for macOS with native Swift implementation

https://github.com/Trans-N-ai/swama
1•jovezhong•49m ago•1 comments

Second ispace craft has probably crash-landed on Moon

https://www.nature.com/articles/d41586-025-01751-3
1•politelemon•51m ago•1 comments

The Automaker Wars No One Talks About

https://www.carsandhorsepower.com/featured/the-automaker-wars-no-one-talks-about-niche-competitions-in-weird-segments
1•Anumbia•52m ago•0 comments

How Anthropic teams use Claude Code [pdf]

https://www-cdn.anthropic.com/58284b19e702b49db9302d5b6f135ad8871e7658.pdf
1•ChrisArchitect•55m ago•0 comments

I Learned Rust in 24 Hours to Eat Free Pizza Morally

https://medium.com/@sebastiancarlos/i-learned-rust-in-24-hours-to-eat-free-pizza-morally-28ea8312e523
1•todsacerdoti•55m ago•0 comments

OpenAI CEO Sam Altman says AI is ready for entry-level jobs

https://fortune.com/2025/06/05/openai-ceo-sam-altman-ai-as-good-as-interns-entry-level-workers-gen-z-embrace-technology/
3•01-_-•59m ago•3 comments

Google confirms more ads on your paid YouTube Premium Lite soon

https://www.neowin.net/news/google-confirms-more-ads-on-your-paid-youtube-premium-lite-soon/
2•01-_-•1h ago•0 comments