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

Method smartFunctionCall

src/llm/QwenLLM.ts:357–375  ·  view source on GitHub ↗

* 自动选择最佳的函数调用方式 * 优先使用 tools 格式,如果不支持则回退到 functions 格式

(
    messages: any[],
    toolsOrFunctions: any[],
    options?: Partial<LLMRequest>
  )

Source from the content-addressed store, hash-verified

355 * 优先使用 tools 格式,如果不支持则回退到 functions 格式
356 */
357 public async smartFunctionCall(
358 messages: any[],
359 toolsOrFunctions: any[],
360 options?: Partial<LLMRequest>
361 ): Promise<any> {
362 try {
363 // 首先尝试使用现代 tools 格式
364 const tools = this.convertToToolsFormat(toolsOrFunctions);
365 return await this.toolsCall(messages, tools, options);
366 } catch (error) {
367 // 如果 tools 格式失败,回退到 functions 格式
368 if (error instanceof Error && error.message.includes('tools')) {
369 console.warn('Qwen: Tools 格式不支持,回退到 functions 格式');
370 const functions = this.convertToFunctionsFormat(toolsOrFunctions);
371 return await this.functionCall(messages, functions, options);
372 }
373 throw error;
374 }
375 }
376
377 /**
378 * 将工具定义转换为 OpenAI Tools 格式

Callers 3

executeToolWorkflowMethod · 0.95
functionCallMethod · 0.80

Calls 5

convertToToolsFormatMethod · 0.95
toolsCallMethod · 0.95
functionCallMethod · 0.95
warnMethod · 0.45

Tested by

no test coverage detected