fix: address code review feedback — schema, comment, key collision, streaming fallback
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
parent
a7a7832674
commit
ebefa1f1da
|
|
@ -413,15 +413,17 @@ async function handleChat(req, res) {
|
||||||
recordProxyFailure(curProv);
|
recordProxyFailure(curProv);
|
||||||
console.error(`[代理] ${curProv} 请求失败: ${err.message}`);
|
console.error(`[代理] ${curProv} 请求失败: ${err.message}`);
|
||||||
|
|
||||||
if (isLastAttempt && !res.headersSent) {
|
// If headers already sent (partial streaming started), can't switch provider
|
||||||
|
if (res.headersSent) return;
|
||||||
|
|
||||||
|
if (isLastAttempt) {
|
||||||
jsonResponse(res, 502, {
|
jsonResponse(res, 502, {
|
||||||
error: true,
|
error: true,
|
||||||
code: 'ALL_PROVIDERS_FAILED',
|
code: 'ALL_PROVIDERS_FAILED',
|
||||||
message: '所有模型提供商均请求失败,请稍后重试'
|
message: '所有模型提供商均请求失败,请稍后重试'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// If not last attempt and headers not sent, try next provider
|
// Otherwise continue to next provider
|
||||||
if (res.headersSent) return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ function generateCandidates(text, source = 'user') {
|
||||||
const end = Math.min(text.length, idx + 80);
|
const end = Math.min(text.length, idx + 80);
|
||||||
const excerpt = text.slice(start, end).replace(/\n/g, ' ').trim();
|
const excerpt = text.slice(start, end).replace(/\n/g, ' ').trim();
|
||||||
|
|
||||||
// 检查中期记忆中的出现次数
|
// 检查中期记忆中的出现次数(使用类型+摘要前40字符作为键,降低碰撞风险)
|
||||||
const memKey = type + ':' + excerpt.slice(0, 20);
|
const memKey = type + ':' + excerpt.slice(0, 40).replace(/\s+/g, '_');
|
||||||
const taskEntry = taskMemory.get(memKey) || { count: 0 };
|
const taskEntry = taskMemory.get(memKey) || { count: 0 };
|
||||||
taskEntry.count++;
|
taskEntry.count++;
|
||||||
taskEntry.lastSeen = Date.now();
|
taskEntry.lastSeen = Date.now();
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ function isInCooldown(provider, model) {
|
||||||
failureLog.delete(key);
|
failureLog.delete(key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return entry.count >= 3; // 5分钟内失败3次以上才冷却
|
return entry.count >= 3; // 5分钟内失败3次及以上才冷却
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
"ghUser": { "type": "string", "description": "GitHub 用户名" },
|
"ghUser": { "type": "string", "description": "GitHub 用户名" },
|
||||||
"role": { "type": "string", "enum": ["founder", "supreme", "main", "dev", "guest"] },
|
"role": { "type": "string", "enum": ["founder", "supreme", "main", "dev", "guest"] },
|
||||||
"mode": { "type": "string", "enum": ["chat", "build", "review", "brain"] },
|
"mode": { "type": "string", "enum": ["chat", "build", "review", "brain"] },
|
||||||
|
"text": { "type": "string", "description": "当前用户输入文本(用于自动检测模式)" },
|
||||||
"devStatus": { "type": "object", "description": "开发者状态" }
|
"devStatus": { "type": "object", "description": "开发者状态" }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue