MCPcopy Create free account
hub / github.com/echoVic/blade-code / convertToFunctionsFormat

Method convertToFunctionsFormat

src/llm/QwenLLM.ts:422–453  ·  view source on GitHub ↗

* 将工具定义转换为旧的 Functions 格式(向后兼容)

(toolsOrFunctions: any[])

Source from the content-addressed store, hash-verified

420 * 将工具定义转换为旧的 Functions 格式(向后兼容)
421 */
422 private convertToFunctionsFormat(toolsOrFunctions: any[]): any[] {
423 return toolsOrFunctions.map(item => {
424 // 如果已经是 functions 格式,直接返回
425 if (item.name && item.description && item.parameters && !item.type) {
426 return item;
427 }
428
429 // 如果是 tools 格式,转换为 functions 格式
430 if (item.type === 'function' && item.function) {
431 return {
432 name: item.function.name,
433 description: item.function.description,
434 parameters: item.function.parameters,
435 };
436 }
437
438 // 如果是项目内部的 ToolDefinition 格式,转换为 functions 格式
439 if (item.name && item.description && item.parameters) {
440 return {
441 name: item.name,
442 description: item.description,
443 parameters: {
444 type: 'object',
445 properties: item.parameters,
446 required: item.required || [],
447 },
448 };
449 }
450
451 return item;
452 });
453 }
454
455 /**
456 * 解析 function call 或 tool call 的结果

Callers 1

smartFunctionCallMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected