01 / DECIDE
架構決策
當 perceived latency 與漸進回饋比一次取得完整 payload 更重要時使用。
可用的 stream 要區分 start、typed delta、tool activity、completion、cancellation 與 failure,而不是只累加文字。 先把 input、output、state 與 side effect 畫成一條可觀察路徑,再決定 把 streaming 設計成狀態機 要放在哪一層。
02 / BUILD
三步實作
- 01
框定合約
先寫下 caller、資料分類、成功條件、timeout、取消與 ownership。當 perceived latency 與漸進回饋比一次取得完整 payload 更重要時使用。
- 02
建立單一路徑
只實作一條 end-to-end path,保留 request correlation、typed state 與可逆 failure handling。可用的 stream 要區分 start、typed delta、tool activity、completion、cancellation 與 failure,而不是只累加文字。
- 03
證明結果
把驗收寫成可重跑的 fixture、contract test 或 browser test。Browser test 涵蓋 abort、reconnect、slow consumer、malformed event,以及 text 中穿插 tool call。
03 / BOUND
Production 邊界
Partial text 尚未可信且可能修訂;terminal event 通過驗證前不可觸發 side effect 或保存 final record。
04 / PROVE
驗收證據
Browser test 涵蓋 abort、reconnect、slow consumer、malformed event,以及 text 中穿插 tool call。
SOURCE / HTTP
可重現來源探針
curl -fsSI 'https://developers.openai.com/api/docs/guides/streaming-responses' | sed -n '1,5p'