fix: validate empty messages + trim relay host whitespace
Address code review: check for empty messages array in relay, and trim whitespace from CN_RELAY_HOST to avoid silent connection failures. Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/04495ae8-6c76-4458-bbb0-262e3205dccd Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
parent
f8824ac43f
commit
d457ccd746
|
|
@ -28,7 +28,7 @@ const http = require('http');
|
||||||
// ─── 广州CN中继配置 ───
|
// ─── 广州CN中继配置 ───
|
||||||
// 当配置了 ZY_CN_LLM_RELAY_HOST 时,请求走广州中继(国内直连·低延迟)
|
// 当配置了 ZY_CN_LLM_RELAY_HOST 时,请求走广州中继(国内直连·低延迟)
|
||||||
// 广州不可达时降级为直连国内API(跨境·高延迟但可用)
|
// 广州不可达时降级为直连国内API(跨境·高延迟但可用)
|
||||||
const CN_RELAY_HOST = process.env.ZY_CN_LLM_RELAY_HOST || '';
|
const CN_RELAY_HOST = (process.env.ZY_CN_LLM_RELAY_HOST || '').trim();
|
||||||
const CN_RELAY_PORT = parseInt(process.env.ZY_CN_LLM_RELAY_PORT || '3900', 10);
|
const CN_RELAY_PORT = parseInt(process.env.ZY_CN_LLM_RELAY_PORT || '3900', 10);
|
||||||
const CN_RELAY_KEY = process.env.ZY_CN_LLM_RELAY_KEY || '';
|
const CN_RELAY_KEY = process.env.ZY_CN_LLM_RELAY_KEY || '';
|
||||||
const CN_RELAY_TIMEOUT = parseInt(process.env.ZY_CN_LLM_RELAY_TIMEOUT || '30000', 10);
|
const CN_RELAY_TIMEOUT = parseInt(process.env.ZY_CN_LLM_RELAY_TIMEOUT || '30000', 10);
|
||||||
|
|
|
||||||
|
|
@ -203,10 +203,10 @@ app.post('/llm/chat', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { messages, model_id, temperature, max_tokens, fallback_order } = req.body;
|
const { messages, model_id, temperature, max_tokens, fallback_order } = req.body;
|
||||||
|
|
||||||
if (!messages || !Array.isArray(messages)) {
|
if (!messages || !Array.isArray(messages) || messages.length === 0) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: true,
|
error: true,
|
||||||
message: '缺少messages参数'
|
message: '缺少messages参数或消息列表为空'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue