fix: 修复审查发现的两个问题
1. 移除 api-server.js 中重复的启动健康检查代码 2. 恢复 ClaudeConverter 和 OpenAIConverter 中对 googleSearch、url_context、googleMaps 扩展工具的支持
This commit is contained in:
parent
9172401a50
commit
e764075cd9
3 changed files with 63 additions and 21 deletions
|
|
@ -1046,13 +1046,37 @@ export class ClaudeConverter extends BaseConverter {
|
||||||
// 处理工具 - 使用 parametersJsonSchema 格式
|
// 处理工具 - 使用 parametersJsonSchema 格式
|
||||||
if (Array.isArray(claudeRequest.tools) && claudeRequest.tools.length > 0) {
|
if (Array.isArray(claudeRequest.tools) && claudeRequest.tools.length > 0) {
|
||||||
const functionDeclarations = [];
|
const functionDeclarations = [];
|
||||||
|
let googleSearchTool = null;
|
||||||
|
let urlContextTool = null;
|
||||||
|
let googleMapsTool = null;
|
||||||
|
|
||||||
claudeRequest.tools.forEach(tool => {
|
claudeRequest.tools.forEach(tool => {
|
||||||
if (!tool || typeof tool !== 'object' || !tool.name) {
|
if (!tool || typeof tool !== 'object') {
|
||||||
logger.warn("Skipping invalid tool declaration in claudeRequest.tools.");
|
logger.warn("Skipping invalid tool declaration in claudeRequest.tools.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理 google_search 扩展
|
||||||
|
if (tool.google_search) {
|
||||||
|
googleSearchTool = tool.google_search;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 url_context 扩展
|
||||||
|
if (tool.url_context) {
|
||||||
|
urlContextTool = tool.url_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 google_maps 扩展
|
||||||
|
if (tool.googleMaps) {
|
||||||
|
googleMapsTool = tool.googleMaps;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有名称且不是上述扩展,则跳过函数处理
|
||||||
|
if (!tool.name) {
|
||||||
|
logger.warn("Skipping unnamed tool declaration in claudeRequest.tools.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 清理 input_schema
|
// 清理 input_schema
|
||||||
let inputSchema = tool.input_schema;
|
let inputSchema = tool.input_schema;
|
||||||
if (inputSchema && typeof inputSchema === 'object') {
|
if (inputSchema && typeof inputSchema === 'object') {
|
||||||
|
|
@ -1077,10 +1101,20 @@ export class ClaudeConverter extends BaseConverter {
|
||||||
functionDeclarations.push(funcDecl);
|
functionDeclarations.push(funcDecl);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (functionDeclarations.length > 0) {
|
if (functionDeclarations.length > 0 || googleSearchTool || urlContextTool || googleMapsTool) {
|
||||||
geminiRequest.tools = [{
|
geminiRequest.tools = [];
|
||||||
functionDeclarations: functionDeclarations
|
if (functionDeclarations.length > 0) {
|
||||||
}];
|
geminiRequest.tools.push({ functionDeclarations });
|
||||||
|
}
|
||||||
|
if (googleSearchTool) {
|
||||||
|
geminiRequest.tools.push({ googleSearch: googleSearchTool });
|
||||||
|
}
|
||||||
|
if (urlContextTool) {
|
||||||
|
geminiRequest.tools.push({ urlContext: urlContextTool });
|
||||||
|
}
|
||||||
|
if (googleMapsTool) {
|
||||||
|
geminiRequest.tools.push({ googleMaps: googleMapsTool });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1101,6 +1101,8 @@ export class OpenAIConverter extends BaseConverter {
|
||||||
if (openaiRequest.tools?.length) {
|
if (openaiRequest.tools?.length) {
|
||||||
const functionDeclarations = [];
|
const functionDeclarations = [];
|
||||||
let hasGoogleSearch = false;
|
let hasGoogleSearch = false;
|
||||||
|
let hasUrlContext = false;
|
||||||
|
let hasGoogleMaps = false;
|
||||||
|
|
||||||
for (const t of openaiRequest.tools) {
|
for (const t of openaiRequest.tools) {
|
||||||
if (!t || typeof t !== 'object') continue;
|
if (!t || typeof t !== 'object') continue;
|
||||||
|
|
@ -1135,16 +1137,34 @@ export class OpenAIConverter extends BaseConverter {
|
||||||
if (t.google_search) {
|
if (t.google_search) {
|
||||||
hasGoogleSearch = true;
|
hasGoogleSearch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理 url_context 工具
|
||||||
|
if (t.url_context) {
|
||||||
|
hasUrlContext = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 google_maps 工具
|
||||||
|
if (t.google_maps) {
|
||||||
|
hasGoogleMaps = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (functionDeclarations.length > 0 || hasGoogleSearch) {
|
if (functionDeclarations.length > 0 || hasGoogleSearch || hasUrlContext || hasGoogleMaps) {
|
||||||
geminiRequest.tools = [{}];
|
geminiRequest.tools = [];
|
||||||
if (functionDeclarations.length > 0) {
|
if (functionDeclarations.length > 0) {
|
||||||
geminiRequest.tools[0].functionDeclarations = functionDeclarations;
|
geminiRequest.tools.push({ functionDeclarations });
|
||||||
}
|
}
|
||||||
if (hasGoogleSearch) {
|
if (hasGoogleSearch) {
|
||||||
const googleSearchTool = openaiRequest.tools.find(t => t.google_search);
|
const googleSearchTool = openaiRequest.tools.find(t => t.google_search);
|
||||||
geminiRequest.tools[0].googleSearch = googleSearchTool.google_search;
|
geminiRequest.tools.push({ googleSearch: googleSearchTool.google_search });
|
||||||
|
}
|
||||||
|
if (hasUrlContext) {
|
||||||
|
const urlContextTool = openaiRequest.tools.find(t => t.url_context);
|
||||||
|
geminiRequest.tools.push({ urlContext: urlContextTool.url_context });
|
||||||
|
}
|
||||||
|
if (hasGoogleMaps) {
|
||||||
|
const googleMapsTool = openaiRequest.tools.find(t => t.google_maps);
|
||||||
|
geminiRequest.tools.push({ googleMaps: googleMapsTool.google_maps });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -412,18 +412,6 @@ async function startServer() {
|
||||||
logger.info(`[ScheduledHealthCheck] Scheduled every ${interval}ms`);
|
logger.info(`[ScheduledHealthCheck] Scheduled every ${interval}ms`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动时运行健康检查
|
|
||||||
if (scheduledConfig.startupRun !== false) {
|
|
||||||
logger.info('[ScheduledHealthCheck] Running scheduled health check on startup...');
|
|
||||||
setImmediate(async () => {
|
|
||||||
try {
|
|
||||||
await poolManager.performScheduledHealthChecks();
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('[ScheduledHealthCheck] Startup run error:', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置定时任务
|
// 设置定时任务
|
||||||
runHealthCheckTimer(interval);
|
runHealthCheckTimer(interval);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue