fix 修复openai格式流式响应的结束标记问题

This commit is contained in:
shaw
2025-07-22 18:00:24 +08:00
parent e77945a3e3
commit a431778363
7 changed files with 47 additions and 33 deletions

View File

@@ -137,7 +137,7 @@ router.post('/messages', authenticateApiKey, async (req, res) => {
// 处理速率限制
if (error.status === 429) {
if (apiKeyData && req.account) {
if (req.apiKey && req.account) {
await geminiAccountService.setAccountRateLimited(req.account.id, true);
}
}

View File

@@ -265,9 +265,13 @@ async function handleChatCompletion(req, res, apiKeyData) {
}
},
// 流转换器
(chunk) => {
return openaiToClaude.convertStreamChunk(chunk, req.body.model);
},
(() => {
// 为每个请求创建独立的会话ID
const sessionId = `chatcmpl-${Math.random().toString(36).substring(2, 15)}${Math.random().toString(36).substring(2, 15)}`;
return (chunk) => {
return openaiToClaude.convertStreamChunk(chunk, req.body.model, sessionId);
};
})(),
{ betaHeader: 'oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14' }
);

View File

@@ -48,13 +48,7 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => {
model = 'gemini-2.0-flash-exp',
temperature = 0.7,
max_tokens = 4096,
stream = false,
n = 1,
stop = null,
presence_penalty = 0,
frequency_penalty = 0,
logit_bias = null,
user = null
stream = false
} = req.body;
// 验证必需参数
@@ -159,7 +153,7 @@ router.post('/v1/chat/completions', authenticateApiKey, async (req, res) => {
// 处理速率限制
if (error.status === 429) {
if (apiKeyData && req.account) {
if (req.apiKey && req.account) {
await geminiAccountService.setAccountRateLimited(req.account.id, true);
}
}