fix(sse): 系统模型 - 恢复 SSE 增量传输
集成 PR #257,保留原 PR 开发者为提交作者。
This commit is contained in:
1 parent
d2a35e10d8
commit
cd42afdfdd
7 files changed
+233
-14
No files matched your search
@@ -124,9 +124,9 @@ curl -fsSL https://raw.githubusercontent.com/ddcat-ai/open-ai-canvas/main/script
|
||||
|
||||
部署配置和 PostgreSQL 密码保存在 `/opt/open-ai-canvas/.env`,不要发送给他人,也不要删除 `backend-data`、`postgres-data` 和 `redis-data` 数据卷。数据卷持久化不等于备份,请定期备份 PostgreSQL 和上传文件。直接使用 IP 访问仅适合首次配置;公网长期使用必须绑定域名并配置 HTTPS。
|
||||
|
||||
## 生产环境文本 SSE
|
||||
## 生产环境 SSE
|
||||
|
||||
文本任务事件流是登录态接口 `GET /api/tasks/:id/text-events`。它只发送当前用户有权限访问的文本任务增量,响应类型为 `text/event-stream`;事件 `delta` 的 `id` 是单调递增的文本序号,`terminal` 表示任务已经成功、失败或取消。生产反向代理必须对这一条路径关闭响应缓冲和缓存,并允许长时间读取;不要把这些设置复制到所有 `/api/` 请求上。
|
||||
文本任务事件流是登录态接口 `GET /api/tasks/:id/text-events`。它只发送当前用户有权限访问的文本任务增量,响应类型为 `text/event-stream`;事件 `delta` 的 `id` 是单调递增的文本序号,`terminal` 表示任务已经成功、失败或取消。画布创作对话还会通过 `/api/ai/system/:channelId/responses`、`/chat/completions` 或 Gemini `:streamGenerateContent` 接口直接接收模型事件流。生产反向代理必须只对这些流式路径关闭响应缓冲和缓存,并允许长时间读取;不要把这些设置复制到所有 `/api/` 请求上。
|
||||
|
||||
### Nginx
|
||||
|
||||
@@ -141,15 +141,34 @@ location ~ ^/api/tasks/[^/]+/text-events$ {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header Connection "";
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_pass_header X-Accel-Buffering;
|
||||
gzip off;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
|
||||
location ~ ^/api/ai/system/[^/]+/(?:responses|chat/completions|models/[^/]+:streamGenerateContent)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header Connection "";
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_pass_header X-Accel-Buffering;
|
||||
gzip off;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
```
|
||||
|
||||
项目镜像内的 `nginx.conf` 已包含同等规则,并只对 `/api/tasks/<id>/text-events` 关闭缓冲。外层 Nginx 和镜像内 Nginx 都存在时,两层都要保留该路径的流式设置;任一层重新缓冲都会让浏览器看起来直到任务结束才收到增量。
|
||||
项目镜像内的 `nginx.conf` 已包含同等规则,并只对文本任务和系统模型事件流关闭缓冲。自定义渠道共用 `/api/ai/custom`,由后端仅在上游实际返回 `text/event-stream` 时发送 `X-Accel-Buffering: no`;镜像内 Nginx 会继续向外层代理传递这个信号。外层 Nginx 和镜像内 Nginx 都存在时,任一层重新缓冲都会让浏览器看起来直到模型响应结束才收到增量。
|
||||
|
||||
### Caddy
|
||||
|
||||
@@ -167,6 +186,16 @@ canvas.example.com {
|
||||
header_down Cache-Control "no-cache, no-transform"
|
||||
}
|
||||
|
||||
@systemModelEvents path_regexp systemModelEvents ^/api/ai/system/[^/]+/(responses|chat/completions|models/[^/]+:streamGenerateContent)$
|
||||
reverse_proxy @systemModelEvents 127.0.0.1:3000 {
|
||||
flush_interval -1
|
||||
transport http {
|
||||
read_timeout 1h
|
||||
}
|
||||
header_up X-Forwarded-Proto {scheme}
|
||||
header_down Cache-Control "no-cache, no-transform"
|
||||
}
|
||||
|
||||
reverse_proxy 127.0.0.1:3000
|
||||
}
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user