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•23h ago
Generating simple HTML instead of markdown would have been a solution. But I guess that ship has sailed.
graboy•19h 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.

Self-hosting your own media considered harmful according to YouTube

https://www.jeffgeerling.com/blog/2025/self-hosting-your-own-media-considered-harmful
478•DavideNL•3h ago•165 comments

How Much Energy Does It Take To Think?

https://www.quantamagazine.org/how-much-energy-does-it-take-to-think-20250604/
19•nsoonhui•3h ago•14 comments

The impossible predicament of the death newts

https://crookedtimber.org/2025/06/05/occasional-paper-the-impossible-predicament-of-the-death-newts/
453•bdr•18h ago•160 comments

A maths proof that is only true in Japan

https://www.newscientist.com/article/2482461-the-bizarre-story-of-a-maths-proof-that-is-only-true-in-japan/
23•monksdream•1h ago•6 comments

Tokasaurus: An LLM inference engine for high-throughput workloads

https://scalingintelligence.stanford.edu/blogs/tokasaurus/
160•rsehrlich•11h ago•20 comments

Test Postgres in Python Like SQLite

https://github.com/wey-gu/py-pglite
81•wey-gu•7h ago•25 comments

How we’re responding to The NYT’s data demands in order to protect user privacy

https://openai.com/index/response-to-nyt-data-demands/
159•BUFU•7h ago•153 comments

Show HN: Claude Composer

https://github.com/possibilities/claude-composer
101•mikebannister•9h ago•47 comments

What a developer needs to know about SCIM

https://tesseral.com/blog/what-a-developer-needs-to-know-about-scim
97•noleary•9h ago•19 comments

APL Interpreter – An implementation of APL, written in Haskell (2024)

https://scharenbroch.dev/projects/apl-interpreter/
95•ofalkaed•11h ago•36 comments

Air Lab – A portable and open air quality measuring device

https://networkedartifacts.com/airlab/simulator
391•256dpi•1d ago•165 comments

X changes its terms to bar training of AI models using its content

https://techcrunch.com/2025/06/05/x-changes-its-terms-to-bar-training-of-ai-models-using-its-content/
116•bundie•15h ago•103 comments

Defending adverbs exuberantly if conditionally

https://countercraft.substack.com/p/defending-adverbs-exuberantly-if
28•benbreen•12h ago•7 comments

Show HN: Ask-human-mcp – zero-config human-in-loop hatch to stop hallucinations

https://masonyarbrough.com/blog/ask-human
76•echollama•9h ago•38 comments

Seven Days at the Bin Store

https://defector.com/seven-days-at-the-bin-store
177•zdw•16h ago•84 comments

SkyRoof: New Ham Satellite Tracking and SDR Receiver Software

https://www.rtl-sdr.com/skyroof-new-ham-satellite-tracking-and-sdr-receiver-software/
83•rmason•13h ago•8 comments

Open Source Distilling

https://opensourcedistilling.com/
37•nativeit•6h ago•16 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/
23•01-_-•2h ago•16 comments

Show HN: Lambduck, a Functional Programming Brainfuck

https://imjakingit.github.io/lambduck/
35•jorkingit•9h ago•14 comments

Digital Minister wants open standards and open source as guiding principle

https://www.heise.de/en/news/Digital-Minister-wants-open-standards-and-open-source-as-guiding-principle-10414632.html
13•donutloop•2h ago•4 comments

Converge (YC S23) Well-capitalized New York startup seeks product developers

https://www.runconverge.com/careers
1•thomashlvt•11h ago

I made a search engine worse than Elasticsearch (2024)

https://softwaredoug.com/blog/2024/08/06/i-made-search-worse-elasticsearch
65•softwaredoug•13h ago•7 comments

The Universal Tech Tree

https://asteriskmag.com/issues/10/the-universal-tech-tree
92•mitchbob•3d ago•45 comments

Machine Learning: The Native Language of Biology

https://decodingbiology.substack.com/p/machine-learning-the-native-language
48•us-merul•9h ago•18 comments

I do not remember my life and it's fine

https://aethermug.com/posts/i-do-not-remember-my-life-and-it-s-fine
184•mrcgnc•9h ago•132 comments

Show HN: iOS Screen Time from a REST API

https://www.thescreentimenetwork.com/api/
89•anteloper•14h ago•45 comments

Programming language Dino and its implementation

https://github.com/dino-lang/dino
47•90s_dev•14h ago•14 comments

Eleven v3

https://elevenlabs.io/v3
225•robertvc•13h ago•123 comments

Homeless but self taught full stack developer

11•crlapples•2h ago•8 comments

How Common Is Multiple Invention?

https://www.construction-physics.com/p/how-often-do-inventions-have-multiple
39•rbanffy•11h ago•27 comments