项目地址:https://github.com/partxic/aigateway
commit:https://github.com/partxic/aigateway/commit/941f5a65624b625cfdeb7ee1f4d6e9007aa8b87a
问题概述:无法长对话,AI 回复时间一长就会 Worker exceeded CPU time limit.
问题原因:
for await (const chunk of resp.body) {
res.write(chunk)
}
res.end()
会反复读入读出 Worker,消耗 CPU 时间
解决方案:
重构 compat 路由,使其脱离 express 框架,使用原生 Worker 写法实现
实际测试:
经过 5 论对话,共计生成 14K Token,依然保持结果完整
现有迁移:
使用 github 的 sync fork 功能,同步代码即可,只需重新更改 wrangler.jsonc 即可无缝迁移
6
19


19 条回复
排序