跳到主要内容Skip to main content

流式输出Streaming Output

Streaming Output

  • 硬件与部署Hardware & deployment
  • 第二站 · 上手Station 2 · Hands On
解决什么问题What problem it solves

回答边生成边推送:你看到逐字出现,而不是等全文算完。Answers stream out as they are generated: you read word by word instead of waiting for the full text.

这是什么What it is

自回归模型逐 token 生成,流式模式把每个 token 即时推送给客户端。

常见实现是 SSE(服务器推送事件流):服务器以事件流持续下发。

价值在首字延迟:长回答不必等全部算完才开始读。

中途可停:取消请求即停止生成与计费。

Autoregressive models generate token by token; streaming pushes each token to the client immediately.

A common implementation is SSE (server-sent events): the server delivers a continuous event stream.

The value is time-to-first-token: long answers don't wait for full computation before you start reading.

It can be stopped mid-way: canceling the request stops generation and billing.

为什么需要知道Why it matters

聊天界面的逐字效果、为什么能中途打断、为什么按输出 token 计费——都来自这个机制。The word-by-word effect in chat UIs, why you can interrupt, why output tokens are billed — all come from this mechanism.

出处Sources
  • MDN《Using server-sent events》(SSE 事件流机制的权威文档)MDN: Using server-sent events (SSE) ↗
  • GPT-3 论文(自回归逐 token 生成的定义)GPT-3 paper (autoregressive token-by-token generation) ↗