blog.est.im

AI 流式接口的pattern (opens in new tab)

AI 现在调用都走 OpenAI-like 接口,遇到长任务多半会走 stream=true 然后AI能力也多半会接力返回给下游,比如浏览器 那么问题来了。下游如果连接断开,是不是就意味着服务器得把AI的输出接住,然后下一次请求接着吐? 如果下一次请求不路由到这个节点和进程,意味着接住要设计一套缓存 更麻烦的是,现代web框架一般都是请求 - 响应模式的,如果浏览器断开连接,按正常流程,后端也会抛出异常之类的中断 所以“接AI的话”这玩意实际上设计还要考虑挺多东西,很麻烦??? 这个问题丢给 ChatGPT它这么回答: 断了就断了,不续传。用户重新发起请求,后端重新生成,最多靠 prompt cache / KV cache / 上下文缓存降低重复成本。很多产品其实就是这么干的,因为实现成本最低。 尼玛。又学到一招。人脑还是想复杂了。 btw 吐槽一下现在 vibe coding 开发者估计很少有人会去在意这些细节了。

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help