Merge pull request #303 from majie776/main

修复某些客户端没有接收到流结束信息后的错误
This commit is contained in:
何夕2077 2026-02-04 16:40:12 +08:00 committed by GitHub
commit 20e476219a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -491,6 +491,17 @@ export async function handleStreamRequest(res, service, model, requestBody, from
responseClosed = true;
} finally {
if (!responseClosed) {
// 根据客户端协议发送相应的流式结束标记
const clientProtocol = getProtocolPrefix(fromProvider);
if (clientProtocol === MODEL_PROTOCOL_PREFIX.OPENAI) {
res.write('data: [DONE]\n\n');
} else if (clientProtocol === MODEL_PROTOCOL_PREFIX.OPENAI_RESPONSES) {
res.write('event: done\n');
res.write('data: {}\n\n');
} else if (clientProtocol === MODEL_PROTOCOL_PREFIX.CLAUDE) {
res.write('event: message_stop\n');
res.write('data: {"type":"message_stop"}\n\n');
}
res.end();
}
await logConversation('output', fullResponseText, PROMPT_LOG_MODE, PROMPT_LOG_FILENAME);