chatgpt-web
chatgpt-web copied to clipboard
Enable SSE api for text-stream
- 同官网接口一致,启用SSE请求协议
- 为了近一步减少流量,简化了stream相关的消息体,其他暂时用不到的字段先忽略不输出
- 同时提升参数csid(即conversionId)的位置
interface StreamMessage {
id: string
csid?: string
pmid?: string
delta: string
text?: string
finishReason?: string
}
- 相应的,添加服务接口
/api/chat-sse
,用于实现 'text/event-stream' 输出
修订了在接收消息的过程中只使用delta,如图
text只出现在最后一波
官方API和accessToken(通过代理)方式都已测试通过。 @Chanzhaoyu
应该不需要这么复杂
import { PassThrough } from "stream";
// 请求里
const steamData = new PassThrough();
ctx.body = steamData;
steamData.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`);
这样就可以了 拉了你的代码用vercel依旧没法实现打字机效果
应该不需要这么复杂
import { PassThrough } from "stream"; // 请求里 const steamData = new PassThrough(); ctx.body = steamData; steamData.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`);
这样就可以了 拉了你的代码用vercel依旧没法实现打字机效果
我的这个版本在SG表现正常(一次一词)、HK表现不太正常(一次约5-20词),应该和网络速度有关。
另外,你这段代码加在哪里?可否方便提个PR看看。