Python (OpenAI SDK)
stream = client.chat.completions.create(model=..., stream=True, ...)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")浏览器 (EventSource)
const evt = new EventSource("/api/v1/chat?stream=1");
evt.onmessage = e => render(JSON.parse(e.data));